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


##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotAggregateTypeArgumentRewriteRule.java:
##########
@@ -158,7 +186,24 @@ private static String getDataTypeArgument(AggregateCall 
aggCall, RelNode input)
         return "UUID";
       default:
         throw new IllegalArgumentException(
-            String.format("Unsupported data type for %s(dataColumn, 
timeColumn): %s", name, dataType));
+            String.format("Unsupported data type for %s(%s): %s", name, 
arguments, dataType));
+    }
+  }
+
+  /// The result type of ANY_VALUE follows its data argument, so an explicit 
data type argument must be the one this
+  /// rule supplies for it.
+  private static void checkAnyValueDataTypeArgument(String name, List<Integer> 
argList, RelNode input) {
+    RelDataType relDataType = 
input.getRowType().getFieldList().get(argList.get(0)).getType();
+    String dataType = inferDataType(name, "expr", relDataType);
+    RelNode unboxedInput = PinotRuleUtils.unboxRel(input);
+    RexNode dataTypeArgument =
+        unboxedInput instanceof Project ? ((Project) 
unboxedInput).getProjects().get(argList.get(1)) : null;
+    String explicitDataType =
+        dataTypeArgument instanceof RexLiteral ? ((RexLiteral) 
dataTypeArgument).getValueAs(String.class) : null;

Review Comment:
   Nit: when `unboxedInput` isn't a `Project` (or the arg isn't a 
`RexLiteral`), `explicitDataType` is null and this throws the mismatch error 
with the raw `dataTypeArgument` in the message. That's the right outcome, but 
the message reads as a type mismatch rather than "non-literal data type"; a 
tiny wording tweak could make that case clearer. Non-blocking.



##########
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.
+    String value = 
clusterConfigs.get(Broker.CONFIG_OF_BROKER_QUERY_INFER_ANY_VALUE_TYPE);
+    boolean enabled = _brokerConfEnabled;
+    if (value != null && ("true".equalsIgnoreCase(value.trim()) || 
"false".equalsIgnoreCase(value.trim()))) {

Review Comment:
   Minor: the parse accepts only literal `true`/`false` and logs+falls back on 
anything else, which is stricter and safer than `Boolean.parseBoolean`. Worth a 
one-line comment noting the intentional strictness, since it differs from how 
most other boolean cluster configs here are read.



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