Skip to content

Commit 4603c54

Browse files
Pablo PudginoMBkkt
authored andcommitted
feat: Add Window Functions
1 parent b94fc4d commit 4603c54

33 files changed

+2378
-68
lines changed

axiom/logical_plan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_library(
1919
LogicalPlanNode.cpp
2020
PlanPrinter.cpp
2121
ExprApi.cpp
22+
Utils.cpp
2223
)
2324

2425
target_link_libraries(axiom_logical_plan velox_type)

axiom/logical_plan/Expr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ class WindowExpr : public Expr {
576576
partitionKeys_{std::move(partitionKeys)},
577577
ordering_{std::move(ordering)},
578578
frame_{std::move(frame)},
579-
ignoreNulls_{ignoreNulls} {}
579+
ignoreNulls_{ignoreNulls} {
580+
VELOX_USER_CHECK(!name_.empty());
581+
}
580582

581583
const std::string& name() const {
582584
return name_;

axiom/logical_plan/ExprPrinter.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,59 @@ class ToTextVisitor : public ExprVisitor {
103103
out << expr.name();
104104
appendInputs(expr, out, context);
105105

106-
// TODO Add partitionKeys, ordering, frame, ignoreNulls.
106+
if (expr.ignoreNulls()) {
107+
out << " IGNORE NULLS";
108+
}
109+
110+
out << " OVER (";
111+
112+
if (!expr.partitionKeys().empty()) {
113+
out << "PARTITION BY ";
114+
for (auto i = 0; i < expr.partitionKeys().size(); ++i) {
115+
if (i > 0) {
116+
out << ", ";
117+
}
118+
expr.partitionKeys()[i]->accept(*this, context);
119+
}
120+
}
121+
122+
if (!expr.ordering().empty()) {
123+
if (!expr.partitionKeys().empty()) {
124+
out << " ";
125+
}
126+
out << "ORDER BY ";
127+
for (auto i = 0; i < expr.ordering().size(); ++i) {
128+
if (i > 0) {
129+
out << ", ";
130+
}
131+
expr.ordering()[i].expression->accept(*this, context);
132+
out << " " << expr.ordering()[i].order.toString();
133+
}
134+
}
135+
136+
const auto& frame = expr.frame();
137+
if (!expr.partitionKeys().empty() || !expr.ordering().empty()) {
138+
out << " ";
139+
}
140+
out << WindowExpr::toName(frame.type) << " BETWEEN ";
141+
142+
// Start bound
143+
if (frame.startValue != nullptr) {
144+
frame.startValue->accept(*this, context);
145+
out << " ";
146+
}
147+
out << WindowExpr::toName(frame.startType);
148+
149+
out << " AND ";
150+
151+
// End bound
152+
if (frame.endValue != nullptr) {
153+
frame.endValue->accept(*this, context);
154+
out << " ";
155+
}
156+
out << WindowExpr::toName(frame.endType);
157+
158+
out << ")";
107159
}
108160

109161
void visit(const ConstantExpr& expr, ExprVisitorContext& context)

0 commit comments

Comments
 (0)