capistrant commented on code in PR #19675:
URL: https://github.com/apache/druid/pull/19675#discussion_r3560383882


##########
processing/src/main/java/org/apache/druid/segment/column/ConstantColumns.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.column;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.segment.data.ConstantColumnarInts;
+import org.apache.druid.segment.data.GenericIndexed;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Fabricates in-memory {@link BaseColumnHolder}s for columns whose value is 
constant across every row, without any
+ * on-disk data. This is the runtime analogue of {@link 
org.apache.druid.segment.serde.NullColumnPartSerde} for
+ * arbitrary constants: a STRING constant is presented as a single-value 
{@link StringUtf8DictionaryEncodedColumn}
+ * (backed by a one-entry dictionary), and numeric constants as a {@link 
ConstantNumericColumn}.
+ */
+public final class ConstantColumns
+{
+  private ConstantColumns()
+  {
+    // no instantiation
+  }
+
+  /**
+   * Add a constant column (via {@link #makeConstantColumnHolder}) to {@code 
target} for each column in
+   * {@code clusteringColumns}, using the group-constant value at the matching 
position of {@code clusteringValues}.
+   */
+  public static void addConstantClusteringColumns(
+      Map<String, Supplier<BaseColumnHolder>> target,
+      RowSignature clusteringColumns,
+      Object[] clusteringValues,
+      int numRows,
+      BitmapFactory bitmapFactory
+  )
+  {
+    for (int i = 0; i < clusteringColumns.size(); i++) {
+      final String columnName = clusteringColumns.getColumnName(i);
+      final ColumnType columnType = clusteringColumns.getColumnType(i)
+                                                     .orElseThrow(() -> 
DruidException.defensive(
+                                                         "clustering column 
[%s] is missing a type",
+                                                         columnName
+                                                     ));
+      final BaseColumnHolder holder = makeConstantColumnHolder(columnType, 
clusteringValues[i], numRows, bitmapFactory);

Review Comment:
   putting trust in caller to pass a good clusteringValues array. bad callsite 
use could index oob. perhaps worth a defensive size comparison with 
clusteringColumns



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