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


##########
processing/src/main/java/org/apache/druid/query/operator/AbstractPartitioningOperator.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.RE;
+import org.apache.druid.query.rowsandcols.RowsAndColumns;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+public abstract class AbstractPartitioningOperator implements Operator
+{
+  protected final List<String> partitionColumns;
+  protected final Operator child;
+
+  public AbstractPartitioningOperator(
+      List<String> partitionColumns,
+      Operator child
+  )
+  {
+    this.partitionColumns = partitionColumns;
+    this.child = child;
+  }
+
+  protected static class Continuation implements Closeable
+  {
+    Iterator<RowsAndColumns> iter;
+    Closeable subContinuation;
+
+    public Continuation(Iterator<RowsAndColumns> iter, Closeable 
subContinuation)
+    {
+      this.iter = iter;
+      this.subContinuation = subContinuation;
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+      if (subContinuation != null) {
+        subContinuation.close();
+      }
+    }
+  }
+
+  protected Signal handlePush(RowsAndColumns rac, Receiver receiver, 
AtomicReference<Iterator<RowsAndColumns>> iterHolder)
+  {
+    if (rac == null) {
+      throw DruidException.defensive("Should never get a null rac here.");
+    }
+
+    Iterator<RowsAndColumns> partitionsIter = getIteratorForRAC(rac);
+
+    AtomicReference<Signal> keepItGoing = new AtomicReference<>(Signal.GO);

Review Comment:
   It forces us to return null in `GlueingPartitioningOperator` (as we need to 
return something):
   ```java
     @Override
     protected Signal handleKeepItGoing(Iterator<RowsAndColumns> iterator, 
Receiver receiver)
     {
       RowsAndColumns rowsAndColumns = iterator.next();
       if (iterator.hasNext()) {
         return receiver.push(rowsAndColumns);
       } else {
         previousRac = rowsAndColumns;
         return null;
       }
     }
   ```
   
   And then we have to handle the null specifically, as we don't want to update 
the signal in the case of null, since handlePush() needs to return the last 
non-null signal.
   ```java
       Signal keepItGoing = Signal.GO;
       while (keepItGoing == Signal.GO && partitionsIter.hasNext()) {
         Signal signal = handleKeepItGoing(partitionsIter, receiver);
         if (signal != null) {
           keepItGoing = signal;
         }
       }
   ```
   
   This didn't seem clean to me, so I ended up going with the AtomicRef 
approach.



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