You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "walterddr (via GitHub)" <gi...@apache.org> on 2023/07/13 23:30:34 UTC

[GitHub] [pinot] walterddr opened a new pull request, #11105: [multistage][agg] support agg with literal arguments

walterddr opened a new pull request, #11105:
URL: https://github.com/apache/pinot/pull/11105

   (no comment)


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr merged pull request #11105: [multistage][agg] support agg with literal arguments

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr merged PR #11105:
URL: https://github.com/apache/pinot/pull/11105


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr commented on a diff in pull request #11105: [multistage][agg] support agg with literal arguments

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #11105:
URL: https://github.com/apache/pinot/pull/11105#discussion_r1266992920


##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/hint/PinotHintStrategyTable.java:
##########
@@ -90,4 +111,33 @@ public static String getHintOption(List<RelHint> hintList, String hintName, Stri
     }
     return null;
   }
+
+  /**
+   * Replace the option value by option key in the {@link RelHint#kvOptions}. the option key is looked up from the
+   * specified hint name for a hint-able {@link org.apache.calcite.rel.RelNode}.
+   *
+   * @param oldHintList hint list from the {@link org.apache.calcite.rel.RelNode}.
+   * @param hintName the name of the {@link RelHint}.
+   * @param optionKey the option key to look for in the {@link RelHint#kvOptions}.
+   * @param optionValue the value to be set into {@link RelHint#kvOptions}.
+   */
+  public static List<RelHint> replaceHintOptions(List<RelHint> oldHintList, String hintName, String optionKey,
+      String optionValue) {

Review Comment:
   this is only needed b/c we are modifying the hint to allow RexLiterals to be propagated without creating an extra project. 
   
   since RelHint is not designed to be mutable. it is not an ideal solution, we should mark this function as "do not use it unless you absolutely know what you are doing"



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotAggregateLiteralAttachmentRule.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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.calcite.rel.rules;
+
+import com.google.common.collect.ImmutableList;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.calcite.avatica.util.ByteString;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.hep.HepRelVertex;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.hint.PinotHintOptions;
+import org.apache.calcite.rel.hint.PinotHintStrategyTable;
+import org.apache.calcite.rel.hint.RelHint;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.runtime.Geometries;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.DateString;
+import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Sarg;
+import org.apache.calcite.util.TimeString;
+import org.apache.calcite.util.TimestampString;
+import org.apache.calcite.util.Util;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+
+/**
+ * Special rule to attach Literal to Aggregate call.
+ */
+public class PinotAggregateLiteralAttachmentRule extends RelOptRule {
+  public static final PinotAggregateLiteralAttachmentRule INSTANCE =
+      new PinotAggregateLiteralAttachmentRule(PinotRuleUtils.PINOT_REL_FACTORY);
+
+  public PinotAggregateLiteralAttachmentRule(RelBuilderFactory factory) {
+    super(operand(LogicalAggregate.class, some(operand(LogicalProject.class, any()))), factory, null);
+  }
+
+  @Override
+  public boolean matches(RelOptRuleCall call) {
+    if (call.rels.length < 1) {
+      return false;
+    }
+    if (call.rel(0) instanceof Aggregate) {
+      Aggregate agg = call.rel(0);
+      ImmutableList<RelHint> hints = agg.getHints();
+      return !PinotHintStrategyTable.containsHintOption(hints,
+          PinotHintOptions.INTERNAL_AGG_OPTIONS, PinotHintOptions.InternalAggregateOptions.AGG_CALL_SIGNATURE);
+    }
+    return false;
+  }
+
+  @Override
+  public void onMatch(RelOptRuleCall call) {
+    Aggregate aggregate = call.rel(0);
+    Map<Pair<Integer, Integer>, RexLiteral> rexLiterals = extractRexLiterals(call);
+    List<RelHint> newHints = PinotHintStrategyTable.replaceHintOptions(aggregate.getHints(),
+        PinotHintOptions.INTERNAL_AGG_OPTIONS, PinotHintOptions.InternalAggregateOptions.AGG_CALL_SIGNATURE,
+        createRexLiteralHintsString(rexLiterals));
+    call.transformTo(new LogicalAggregate(aggregate.getCluster(), aggregate.getTraitSet(), newHints,
+        aggregate.getInput(), aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList()));
+  }
+
+  private static Map<Pair<Integer, Integer>, RexLiteral> extractRexLiterals(RelOptRuleCall call) {
+    Aggregate aggregate = call.rel(0);
+    Project project = call.rel(1);
+    List<RexNode> rexNodes = project.getProjects();
+    List<AggregateCall> aggCallList = aggregate.getAggCallList();
+    final Map<Pair<Integer, Integer>, RexLiteral> rexLiteralMap = new HashMap<>();
+    for (int aggIdx = 0; aggIdx < aggCallList.size(); aggIdx++) {
+      AggregateCall aggCall = aggCallList.get(aggIdx);
+      for (int argIdx = 0; argIdx < aggCall.getArgList().size(); argIdx++) {
+        RexNode field = rexNodes.get(aggCall.getArgList().get(argIdx));
+        if (field instanceof RexLiteral) {
+          rexLiteralMap.put(new Pair<>(aggIdx, argIdx), (RexLiteral) field);
+        }
+      }
+    }
+    return rexLiteralMap;
+  }
+
+  private static String createRexLiteralHintsString(Map<Pair<Integer, Integer>, RexLiteral> rexLiterals) {

Review Comment:
   factor these stringify-object conversion to a util



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/AggregateOperator.java:
##########
@@ -234,18 +298,34 @@ private FunctionContext convertRexExpressionsToFunctionContext(RexExpression.Fun
     return functionContext;
   }
 
+  private void rewriteAggArgumentWithLiterals(List<ExpressionContext> aggArguments, int aggIdx,
+      RexExpression.FunctionCall aggFunctionCall) {
+    String functionName = aggFunctionCall.getFunctionName();
+    // This should be provided by AggregationFunctionType indicating which argIdx requires literal.
+    if (functionName.equals("FIRSTWITHTIME") || functionName.equals("LASTWITHTIME")) {
+      aggArguments.add(ExpressionContext.forIdentifier("__PLACEHOLDER__"));
+      aggArguments.add(ExpressionContext.forLiteralContext(_aggCallLiteralArgsMap.get(aggIdx).get(2)));
+    }
+    if (functionName.equals("PERCENTILE")) {
+      aggArguments.add(ExpressionContext.forLiteralContext(_aggCallLiteralArgsMap.get(aggIdx).get(1)));
+    }
+  }

Review Comment:
   this function needs to be replaced by a util in `AggregateFunctionType` that handles each registered function separately. 



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotAggregateExchangeNodeInsertRule.java:
##########
@@ -111,17 +112,18 @@ public void onMatch(RelOptRuleCall call) {
     ImmutableList<RelHint> oldHints = oldAggRel.getHints();
 
     Aggregate newAgg;

Review Comment:
   note to self:
   after this main `onMatch` conversion
   1. we should check if all the Aggregate functions have desired literals put in place
   2. we should make `AggregationFunctionType`s register optional literal checkers on specific operands



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] codecov-commenter commented on pull request #11105: [multistage][agg] support agg with literal arguments

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #11105:
URL: https://github.com/apache/pinot/pull/11105#issuecomment-1641001595

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#11105](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (77bb742) into [master](https://app.codecov.io/gh/apache/pinot/commit/7f855a522026db423c6aa722ffa0907af8c8ee9b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (7f855a5) will **decrease** coverage by `0.01%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #11105      +/-   ##
   ==========================================
   - Coverage    0.11%    0.11%   -0.01%     
   ==========================================
     Files        2203     2204       +1     
     Lines      118141   118293     +152     
     Branches    17877    17907      +30     
   ==========================================
     Hits          137      137              
   - Misses     117984   118136     +152     
     Partials       20       20              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration1temurin11 | `0.00% <0.00%> (ø)` | |
   | integration1temurin17 | `0.00% <0.00%> (ø)` | |
   | integration1temurin20 | `0.00% <0.00%> (ø)` | |
   | integration2temurin11 | `?` | |
   | integration2temurin17 | `?` | |
   | integration2temurin20 | `?` | |
   | unittests1temurin11 | `?` | |
   | unittests1temurin17 | `?` | |
   | unittests1temurin20 | `?` | |
   | unittests2temurin11 | `0.11% <0.00%> (-0.01%)` | :arrow_down: |
   | unittests2temurin17 | `0.11% <0.00%> (-0.01%)` | :arrow_down: |
   | unittests2temurin20 | `0.11% <0.00%> (-0.01%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [.../java/org/apache/pinot/query/QueryEnvironment.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvUXVlcnlFbnZpcm9ubWVudC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../pinot/query/planner/logical/LiteralHintUtils.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9sb2dpY2FsL0xpdGVyYWxIaW50VXRpbHMuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [.../query/planner/logical/RelToPlanNodeConverter.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9sb2dpY2FsL1JlbFRvUGxhbk5vZGVDb252ZXJ0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...pinot/query/planner/plannode/AbstractPlanNode.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9wbGFubm9kZS9BYnN0cmFjdFBsYW5Ob2RlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...he/pinot/query/planner/plannode/AggregateNode.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcGxhbm5lci9wbGFubm9kZS9BZ2dyZWdhdGVOb2RlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...inot/query/runtime/operator/AggregateOperator.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9BZ2dyZWdhdGVPcGVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../pinot/query/runtime/plan/PhysicalPlanVisitor.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9wbGFuL1BoeXNpY2FsUGxhblZpc2l0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...che/pinot/segment/spi/AggregationFunctionType.java](https://app.codecov.io/gh/apache/pinot/pull/11105?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1zcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3Bpbm90L3NlZ21lbnQvc3BpL0FnZ3JlZ2F0aW9uRnVuY3Rpb25UeXBlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   
   ... and [11 files with indirect coverage changes](https://app.codecov.io/gh/apache/pinot/pull/11105/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] xiangfu0 commented on a diff in pull request #11105: [multistage][agg] support agg with literal arguments

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #11105:
URL: https://github.com/apache/pinot/pull/11105#discussion_r1267771638


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/LiteralHintUtils.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.pinot.query.planner.logical;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Pair;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.request.Literal;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class LiteralHintUtils {
+  private LiteralHintUtils() {
+    // do not instantiate.
+  }
+
+  public static String literalMapToHintString(Map<Pair<Integer, Integer>, RexExpression.Literal> literals) {
+    List<String> literalStrings = new ArrayList<>(literals.size());
+    for (Map.Entry<Pair<Integer, Integer>, RexExpression.Literal> e : literals.entrySet()) {
+      literalStrings.add(String.format("%d_%d_%s_%s", e.getKey().left, e.getKey().right,
+          e.getValue().getDataType().name(), e.getValue().getValue()));
+    }
+    return "{" + StringUtils.join(literalStrings, ",") + "}";
+  }
+
+  public static Map<Integer, Map<Integer, Literal>> hintStringToLiteralMap(String literalString) {
+    Map<Integer, Map<Integer, Literal>> aggCallToLiteralArgsMap = new HashMap<>();
+    if (StringUtils.isNotEmpty(literalString) && !"{}".equals(literalString)) {
+      String[] literalStringArr = literalString.substring(1, literalString.length() - 1).split(",");
+      for (String literalStr : literalStringArr) {
+        String[] literalStrParts = literalStr.split("_");

Review Comment:
   `literalStr.split("_", 4);` ?
   What if there is underscore in the `e.getValue().getValue()`



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr commented on a diff in pull request #11105: [multistage][agg] support agg with literal arguments

Posted by "walterddr (via GitHub)" <gi...@apache.org>.
walterddr commented on code in PR #11105:
URL: https://github.com/apache/pinot/pull/11105#discussion_r1268129739


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/LiteralHintUtils.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.pinot.query.planner.logical;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Pair;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.request.Literal;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public class LiteralHintUtils {
+  private LiteralHintUtils() {
+    // do not instantiate.
+  }
+
+  public static String literalMapToHintString(Map<Pair<Integer, Integer>, RexExpression.Literal> literals) {
+    List<String> literalStrings = new ArrayList<>(literals.size());
+    for (Map.Entry<Pair<Integer, Integer>, RexExpression.Literal> e : literals.entrySet()) {
+      literalStrings.add(String.format("%d_%d_%s_%s", e.getKey().left, e.getKey().right,
+          e.getValue().getDataType().name(), e.getValue().getValue()));
+    }
+    return "{" + StringUtils.join(literalStrings, ",") + "}";
+  }
+
+  public static Map<Integer, Map<Integer, Literal>> hintStringToLiteralMap(String literalString) {
+    Map<Integer, Map<Integer, Literal>> aggCallToLiteralArgsMap = new HashMap<>();
+    if (StringUtils.isNotEmpty(literalString) && !"{}".equals(literalString)) {
+      String[] literalStringArr = literalString.substring(1, literalString.length() - 1).split(",");
+      for (String literalStr : literalStringArr) {
+        String[] literalStrParts = literalStr.split("_");

Review Comment:
   good point. and we shouldn't use `_` b/c some valid type name contains underscore



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org