somandal commented on code in PR #10635:
URL: https://github.com/apache/pinot/pull/10635#discussion_r1175457046


##########
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");

Review Comment:
   @siddharthteotia what do you mean by random `Identifier` here exactly? We 
need to essentially project one value per row in the input. We discussed two 
ways to do this:
   
   a) Project one of the columns
   b) Project a literal (which will essentially project a random value for each 
row)
   
   We don't care about the actual values of the rows and even something like a 
list of empty objects would do (but we decided to explore this later). 
Projecting a column gets into the business of deciding which one, and some 
types of columns (say string) may result in more data transfer. Let me know if 
you'd like more clarification.



-- 
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]

Reply via email to