somandal commented on code in PR #10635:
URL: https://github.com/apache/pinot/pull/10635#discussion_r1175537604
##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java:
##########
@@ -171,4 +195,59 @@ private boolean isPartitionByOnlyQuery(Window.Group
windowGroup) {
}
return isPartitionByOnly;
}
+
+ /**
+ * Only empty OVER() type queries can result in a situation where the
LogicalProject below the LogicalWindow is an
+ * empty LogicalProject (i.e. no columns are projected). This can only occur
for window functions that don't take
+ * an input column. Some example queries where this can occur are:
+ *
+ * SELECT COUNT(*) OVER() from tableName
+ * SELECT 42, COUNT(*) OVER() from tableName
+ * SELECT ROW_NUMBER() OVER() from tableName
+ *
+ * This function modifies the empty LogicalProject below the LogicalWindow
to add a literal and adds a LogicalProject
+ * above LogicalWindow to remove the additional literal column from being
projected any further. This also handles
+ * the addition of the LogicalExchange under the LogicalWindow.
+ *
+ * TODO: Explore an option to handle empty LogicalProject by actually
projecting empty rows for each entry. This way
+ * there will no longer be a need to add a literal to the empty
LogicalProject, but just traverse the number of
+ * rows
+ */
+ private RelNode handleEmptyProjectBelowWindow(Window window, Project
project) {
+ RelOptCluster cluster = window.getCluster();
+ RexBuilder rexBuilder = cluster.getRexBuilder();
+
+ // Construct the project that goes below the window (which projects a
literal)
+ final List<RexNode> expsForProjectBelowWindow = Collections.singletonList(
+ rexBuilder.makeLiteral(0,
cluster.getTypeFactory().createSqlType(SqlTypeName.INTEGER)));
+ final List<String> expsFieldNamesBelowWindow =
Collections.singletonList("winLiteral");
+ Project projectBelowWindow = LogicalProject.create(project.getInput(),
project.getHints(),
+ expsForProjectBelowWindow, expsFieldNamesBelowWindow);
+
+ // Fix up the inputs to the Window to include the literal column and add
an exchange
+ final RelDataTypeFactory.Builder outputBuilder =
cluster.getTypeFactory().builder();
+ outputBuilder.addAll(projectBelowWindow.getRowType().getFieldList());
+ outputBuilder.addAll(window.getRowType().getFieldList());
+
+ // This scenario is only possible for empty OVER(), add a LogicalExchange
with empty hash distribution list
Review Comment:
done, please take a look. This function has some java docs that explain in
detail where this modification is necessary
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]