xiangfu0 commented on code in PR #19990:
URL: https://github.com/apache/pinot/pull/19990#discussion_r4381360600


##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotAggregateTypeArgumentRewriteRule.java:
##########
@@ -119,17 +131,33 @@ public void onMatch(RelOptRuleCall call) {
   /// Returns the data type argument to append, or `null` when the call 
already has one or is not such a call. Throws
   /// for a data argument without an explicit form, such as an array from a 
multi-value column.
   @Nullable
-  private static String getDataTypeArgument(AggregateCall aggCall, RelNode 
input) {
-    if (aggCall.getArgList().size() != 2) {
-      return null;
-    }
+  private String getDataTypeArgument(AggregateCall aggCall, RelNode input) {
     String name = 
AggregationFunctionType.getNormalizedAggregationFunctionName(aggCall.getAggregation().getName());
-    if (!name.equals(AggregationFunctionType.FIRSTWITHTIME.name())
-        && !name.equals(AggregationFunctionType.LASTWITHTIME.name())) {
+    List<Integer> argList = aggCall.getArgList();
+    String arguments;
+    if (name.equals(AggregationFunctionType.FIRSTWITHTIME.name())
+        || name.equals(AggregationFunctionType.LASTWITHTIME.name())) {
+      if (argList.size() != 2) {
+        return null;
+      }
+      arguments = "dataColumn, timeColumn";
+    } else if (name.equals(AggregationFunctionType.ANYVALUE.name())) {
+      if (argList.size() == 2) {
+        checkAnyValueDataTypeArgument(name, argList, input);
+        return null;
+      }
+      if (!_rewriteAnyValue) {
+        return null;
+      }
+      arguments = "expr";
+    } else {
       return null;
     }
-    SqlTypeName dataType =
-        
input.getRowType().getFieldList().get(aggCall.getArgList().get(0)).getType().getSqlTypeName();
+    return inferDataType(name, arguments, 
input.getRowType().getFieldList().get(argList.get(0)).getType());

Review Comment:
   Changed in a8ab4e2b47: ANY_VALUE now maps through 
`RelToPlanNodeConverter.convertToColumnDataType`, so a DECIMAL expression with 
a scale gets 'DOUBLE' (INT/LONG/BIG_DECIMAL for scale 0), with runtime cases 
that put an infinite row in the block (leaf and skip-leaf); 
FIRST/LAST_WITH_TIME keeps #19986's mapping here and is left for a separate fix.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AnyValueAggregationFunction.java:
##########
@@ -200,7 +249,7 @@ private void aggregateHelper(int length, BlockValSet bvs, 
ValueProcessor<Object>
       // Fall back to direct value access based on type
       forEachNotNull(length, bvs, (from, to) -> {
         for (int i = from; i < to; i++) {
-          Object value = getDirectValue(bvs, i);
+          Object value = getDirectValue(bvs, i, storedType);

Review Comment:
   Changed in a8ab4e2b47: the kernel fetches the value array once per block and 
reads a row only when its group has no value yet, with a test that the array is 
fetched once.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/InferAnyValueTypeProvider.java:
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.pinot.broker.requesthandler;
+
+import java.util.Map;
+import java.util.Set;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants.Broker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Resolves the default of the `inferAnyValueType` query option from
+/// [Broker#CONFIG_OF_BROKER_QUERY_INFER_ANY_VALUE_TYPE] in the broker conf 
and in the Helix cluster config. The cluster
+/// config wins where it sets the key, and it is applied live: registered as a 
[PinotClusterConfigChangeListener], a
+/// change takes effect on the next query without a broker restart.
+///
+/// Thread-safe.
+public class InferAnyValueTypeProvider implements 
PinotClusterConfigChangeListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(InferAnyValueTypeProvider.class);
+
+  private final boolean _brokerConfEnabled;
+  private volatile boolean _enabled;
+
+  public InferAnyValueTypeProvider(PinotConfiguration config) {
+    _brokerConfEnabled = 
config.getProperty(Broker.CONFIG_OF_BROKER_QUERY_INFER_ANY_VALUE_TYPE,
+        Broker.DEFAULT_BROKER_QUERY_INFER_ANY_VALUE_TYPE);
+    _enabled = _brokerConfEnabled;
+  }
+
+  @Override
+  public void onChange(Set<String> changedConfigs, Map<String, String> 
clusterConfigs) {
+    if 
(!changedConfigs.contains(Broker.CONFIG_OF_BROKER_QUERY_INFER_ANY_VALUE_TYPE)) {
+      return;
+    }
+    // A removed or invalid value falls back to the broker conf, so that a 
broker that restarts resolves the same.

Review Comment:
   Changed in a8ab4e2b47: `BaseBrokerStarter.init()` now pins 
`pinot.broker.query.infer.any.value.type` before `applyClusterConfig`, as 
#20038 does for fingerprinting.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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