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


##########
processing/src/main/java/org/apache/druid/segment/column/ConstantNumericColumn.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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 org.apache.druid.math.expr.ExprEval;
+import org.apache.druid.math.expr.ExpressionType;
+import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.ConstantExprEvalSelector;
+import org.apache.druid.segment.data.ReadableOffset;
+import org.apache.druid.segment.vector.ConstantVectorSelectors;
+import org.apache.druid.segment.vector.ReadableVectorOffset;
+import org.apache.druid.segment.vector.VectorObjectSelector;
+import org.apache.druid.segment.vector.VectorValueSelector;
+
+import javax.annotation.Nullable;
+
+/**
+ * A numeric {@link NumericColumn} of a fixed length whose value is the same 
for every row. Selectors are backed by the
+ * shared constant-selector helpers ({@link ConstantExprEvalSelector} / {@link 
ConstantVectorSelectors}). Used to
+ * fabricate a per-group clustering column for a clustered base table 
(constant within the group), but is not otherwise
+ * specific to clustered segments.
+ */
+public final class ConstantNumericColumn implements NumericColumn
+{
+  private final ColumnType type;
+  @Nullable
+  private final Number value;
+  private final int numRows;
+
+  public ConstantNumericColumn(ColumnType type, @Nullable Number value, int 
numRows)
+  {
+    this.type = type;
+    this.value = value;
+    this.numRows = numRows;
+  }
+
+  @Override
+  public int length()
+  {
+    return numRows;
+  }
+
+  @Override
+  public long getLongSingleValueRow(int rowNum)
+  {
+    return value == null ? 0L : value.longValue();
+  }
+
+  @Override
+  public ColumnValueSelector<?> makeColumnValueSelector(ReadableOffset offset)
+  {
+    return new 
ConstantExprEvalSelector(ExprEval.ofType(ExpressionType.fromColumnTypeStrict(type),
 value));

Review Comment:
   [P1] Return boxed numbers from the constant numeric selector
   
   `ConstantExprEvalSelector#getObject()` returns an `ExprEval`, not the boxed 
LONG/FLOAT/DOUBLE expected from a numeric physical column. The deleted 
single-group wrapper explicitly unwrapped `.value()`, and the multi-group 
wrapper still does. When pruning leaves one cluster group, the query now 
bypasses those wrappers and reads this selector directly; `ScanQueryEngine` 
forwards `getObject()` verbatim, so selecting a numeric clustering column 
returns an `ExprEval` or a malformed response, and object-oriented aggregators 
can fail similarly. Use a typed numeric selector or unwrap the expression value 
so `getObject()` returns the boxed value or null.



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