Akshat-Jain commented on code in PR #17038:
URL: https://github.com/apache/druid/pull/17038#discussion_r1793844642


##########
processing/src/test/java/org/apache/druid/query/operator/GlueingPartitioningOperatorTest.java:
##########
@@ -0,0 +1,417 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.query.operator;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.query.operator.window.RowsAndColumnsHelper;
+import org.apache.druid.query.rowsandcols.MapOfColumnsRowsAndColumns;
+import org.apache.druid.query.rowsandcols.RowsAndColumns;
+import org.apache.druid.query.rowsandcols.column.IntArrayColumn;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.function.BiFunction;
+
+public class GlueingPartitioningOperatorTest
+{
+  @Test
+  public void testDefaultImplementation()

Review Comment:
   Done



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/WindowOperatorQueryFrameProcessor.java:
##########
@@ -158,174 +131,73 @@ public List<WritableFrameChannel> outputChannels()
   @Override
   public ReturnOrAwait<Object> runIncrementally(IntSet readableInputs) throws 
IOException
   {
-    /*
-     There are 2 scenarios:
-
-     *** Scenario 1: Query has atleast one window function with an OVER() 
clause without a PARTITION BY ***
-
-     In this scenario, we add all the RACs to a single RowsAndColumns to be 
processed. We do it via ConcatRowsAndColumns, and run all the operators on the 
ConcatRowsAndColumns.
-     This is done because we anyway need to run the operators on the entire 
set of rows when we have an OVER() clause without a PARTITION BY.
-     This scenario corresponds to partitionColumnNames.isEmpty()=true code 
flow.
-
-     *** Scenario 2: All window functions in the query have OVER() clause with 
a PARTITION BY ***
-
-     In this scenario, we need to process rows for each PARTITION BY group 
together, but we can batch multiple PARTITION BY keys into the same RAC before 
passing it to the operators for processing.
-     Batching is fine since the operators list would have the required 
NaivePartitioningOperatorFactory to segregate each PARTITION BY group during 
the processing.
-
-     The flow for this scenario can be summarised as following:
-     1. Frame Reading and Cursor Initialization: We start by reading a frame 
from the inputChannel and initializing frameCursor to iterate over the rows in 
that frame.
-     2. Row Comparison: For each row in the frame, we decide whether it 
belongs to the same PARTITION BY group as the previous row.
-                        This is determined by comparePartitionKeys() method.
-                        Please refer to the Javadoc of that method for further 
details and an example illustration.
-        2.1. If the PARTITION BY columns of current row matches the PARTITION 
BY columns of the previous row,
-             they belong to the same PARTITION BY group, and gets added to 
rowsToProcess.
-             If the number of total rows materialized exceed 
maxRowsMaterialized, we process the pending batch via 
processRowsUpToLastPartition() method.
-        2.2. If they don't match, then we have reached a partition boundary.
-             In this case, we update the value for lastPartitionIndex.
-     3. End of Input: If the input channel is finished, any remaining rows in 
rowsToProcess are processed.
-
-     *Illustration of Row Comparison step*
-
-     Let's say we have window_function() OVER (PARTITION BY A ORDER BY B) in 
our query, and we get 3 frames in the input channel to process.
-
-     Frame 1
-     A, B
-     1, 2
-     1, 3
-     2, 1 --> PARTITION BY key (column A) changed from 1 to 2.
-     2, 2
-
-     Frame 2
-     A, B
-     3, 1 --> PARTITION BY key (column A) changed from 2 to 3.
-     3, 2
-     3, 3
-     3, 4
-
-     Frame 3
-     A, B
-     3, 5
-     3, 6
-     4, 1 --> PARTITION BY key (column A) changed from 3 to 4.
-     4, 2
-
-     *Why batching?*
-     We batch multiple PARTITION BY keys for processing together to avoid the 
overhead of creating different RACs for each PARTITION BY keys, as that would 
be unnecessary in scenarios where we have a large number of PARTITION BY keys, 
but each key having a single row.
-
-     *Future thoughts: https://github.com/apache/druid/issues/16126*
-     Current approach with R&C and operators materialize a single R&C for 
processing. In case of data with low cardinality a single R&C might be too big 
to consume. Same for the case of empty OVER() clause.
-     Most of the window operations like SUM(), RANK(), RANGE() etc. can be 
made with 2 passes of the data. We might think to reimplement them in the MSQ 
way so that we do not have to materialize so much data.
-     */
-
     // If there are rows pending flush, flush them and run again before 
processing any more rows.
     if (frameHasRowsPendingFlush()) {
       flushAllRowsAndCols();
       return ReturnOrAwait.runAgain();
     }
 
-    if (partitionColumnNames.isEmpty()) {
-      // Scenario 1: Query has atleast one window function with an OVER() 
clause without a PARTITION BY.
-      if (inputChannel.canRead()) {
-        final Frame frame = inputChannel.read();
-        convertRowFrameToRowsAndColumns(frame);
-        return ReturnOrAwait.runAgain();
-      }
-
-      if (inputChannel.isFinished()) {
-        // If no rows are flushed yet, process all rows.
-        if (rowId.get() == 0) {
-          runAllOpsOnMultipleRac(frameRowsAndCols);
-        }
+    if (inputChannel.canRead()) {
+      final Frame frame = inputChannel.read();
+      convertRowFrameToRowsAndColumns(frame);

Review Comment:
   Done



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