clintropolis commented on code in PR #19460:
URL: https://github.com/apache/druid/pull/19460#discussion_r3352513448


##########
processing/src/main/java/org/apache/druid/segment/ConcatenatingCursor.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.segment;
+
+import com.google.common.base.Supplier;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.segment.projections.ClusteringColumnSelectorFactory;
+
+import javax.annotation.Nullable;
+import java.util.List;
+
+/**
+ * {@link Cursor} that walks a sequence of per-group cursors back-to-back, 
presenting them to the caller as a single
+ * cursor over a clustered base table. On group transitions the wrapper {@link 
ColumnSelectorFactory} updates its
+ * underlying delegate and clustering values so previously-acquired delegating 
selectors observe the new group's data
+ * on their next access.
+ * <p>
+ * Each entry in {@link #holderSuppliers} is a lazy producer of a {@link 
CursorHolder} for one cluster group. The
+ * outer {@link CursorHolder} owns the lifecycle of the per-group holders.
+ */
+public final class ConcatenatingCursor implements Cursor
+{
+  private final List<Supplier<CursorHolder>> holderSuppliers;
+  private final List<Object[]> clusteringValuesByGroup;
+  private final ClusteringColumnSelectorFactory wrapperFactory;
+
+  private int currentIdx;
+  @Nullable
+  private Cursor currentCursor;
+  private boolean initialized;
+
+  public ConcatenatingCursor(
+      List<Supplier<CursorHolder>> holderSuppliers,
+      List<Object[]> clusteringValuesByGroup,
+      ClusteringColumnSelectorFactory wrapperFactory
+  )
+  {
+    if (holderSuppliers.size() != clusteringValuesByGroup.size()) {
+      throw DruidException.defensive(
+          "holderSuppliers size [%s] must equal clusteringValuesByGroup size 
[%s]",
+          holderSuppliers.size(),
+          clusteringValuesByGroup.size()
+      );
+    }
+    if (holderSuppliers.isEmpty()) {
+      throw DruidException.defensive("ConcatenatingCursor requires at least 
one cluster group");
+    }
+    this.holderSuppliers = holderSuppliers;
+    this.clusteringValuesByGroup = clusteringValuesByGroup;
+    this.wrapperFactory = wrapperFactory;
+    this.currentIdx = -1;
+  }
+
+  private void initializeIfNeeded()
+  {
+    if (initialized) {
+      return;
+    }
+    initialized = true;
+    advanceToNextNonEmptyGroup();
+  }
+
+  /**
+   * Open the next group whose cursor has at least one row. Sets {@code 
currentCursor = null} when all groups are

Review Comment:
   eh, i feel like 'open' is more honest to what is happening though (at least 
on the first pass) since the supplier is computing the cursor holders on the 
fly on the first get as we advance through. with regards to the delegate, we 
don't want to nuke it because it still needs to answer stuff like column 
capabilities that things could be using even after a cursor is done (since 
those metadata methods just delegate to whatever the current group is even 
though they are largely identical across groups)



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