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


##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/hint/PinotHintOptions.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.hint;
+
+/**
+ * {@code PinotHintOptions} specified the supported hint options by Pinot 
based a particular type of relation node.
+ *
+ * <p>for each {@link org.apache.calcite.rel.RelNode} type we support a option 
hint name.</p>

Review Comment:
   nit: an option



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/hint/PinotHintOptions.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.hint;
+
+/**
+ * {@code PinotHintOptions} specified the supported hint options by Pinot 
based a particular type of relation node.
+ *
+ * <p>for each {@link org.apache.calcite.rel.RelNode} type we support a option 
hint name.</p>
+ * <p>for each option hint name there's a corresponding {@link RelHint} that 
supported only key-value option stored
+ * in {@link RelHint#kvOptions}</p>
+ */
+public class PinotHintOptions {
+  public static final String AGGREGATE_HINT_OPTIONS = "aggOptions";
+  public static final String JOIN_HINT_OPTIONS = "joinOptions";
+
+  private PinotHintOptions() {
+    // do not instantiate.
+  }
+
+  public static class AggregateOptions {
+    public static final String IS_PARTITIONED_BY_GROUP_BY_KEYS = 
"partitioned_by_group_by_keys";

Review Comment:
   Shall we use `is_partitioned_by_group_by_keys`? I feel that I need to give a 
list of columns under this option.



##########
pinot-query-planner/src/test/resources/queries/PinotHintablePlans.json:
##########
@@ -0,0 +1,107 @@
+{
+  "pinot_hint_option_tests": {
+    "queries": [
+      {
+        "description": "semi-join with dynamic_broadcast join strategy",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ 
joinOptions(join_strategy='dynamic_broadcast,unknown_hint') */ a.col1, a.col2 
FROM a WHERE a.col1 IN (SELECT col2 FROM b WHERE b.col3 > 0)",
+        "output": [
+          "Execution Plan",
+          "\nLogicalExchange(distribution=[single])",
+          "\n  LogicalJoin(condition=[=($0, $2)], joinType=[semi])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[a]])",
+          "\n    LogicalExchange(distribution=[broadcast])",
+          "\n      LogicalProject(col2=[$1], col3=[$2])",
+          "\n        LogicalFilter(condition=[>($2, 0)])",
+          "\n          LogicalTableScan(table=[[b]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "semi-join with colocated join key",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ 
joinOptions(colocated_by_join_keys) */ * FROM a WHERE a.col1 IN (SELECT col2 
FROM b WHERE b.col3 > 0)",
+        "output": [
+          "Execution Plan",
+          "\nLogicalJoin(condition=[=($0, $5)], joinType=[semi])",
+          "\n  LogicalExchange(distribution=[hash[0]])",
+          "\n    LogicalTableScan(table=[[a]])",
+          "\n  LogicalExchange(distribution=[hash[0]])",
+          "\n    LogicalProject(col2=[$1], col3=[$2])",
+          "\n      LogicalFilter(condition=[>($2, 0)])",
+          "\n        LogicalTableScan(table=[[b]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "semi-join with colocated join key and 
dynamic_broadcast join strategy",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ 
joinOptions(join_strategy='dynamic_broadcast', colocated_by_join_keys='true') 
*/ a.col1, a.col2 FROM a WHERE a.col1 IN (SELECT col2 FROM b WHERE b.col3 > 0)",
+        "output": [
+          "Execution Plan",
+          "\nLogicalExchange(distribution=[single])",
+          "\n  LogicalJoin(condition=[=($0, $2)], joinType=[semi])",
+          "\n    LogicalProject(col1=[$0], col2=[$1])",
+          "\n      LogicalTableScan(table=[[a]])",
+          "\n    LogicalExchange(distribution=[single])",
+          "\n      LogicalProject(col2=[$1], col3=[$2])",
+          "\n        LogicalFilter(condition=[>($2, 0)])",
+          "\n          LogicalTableScan(table=[[b]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "aggregate with skip leaf stage hint, group by 
aggregate",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ skipLeafStageGroupByAggregation */ 
a.col2, a.col1, SUM(a.col3) FROM a WHERE a.col3 >= 0 AND a.col1 = 'a' GROUP BY 
a.col1, a.col2",
+        "output": [
+          "Execution Plan",
+          "\nLogicalProject(col2=[$1], col1=[$0], EXPR$2=[$2])",
+          "\n  LogicalAggregate(group=[{0, 1}], EXPR$2=[$SUM0($2)])",
+          "\n    LogicalExchange(distribution=[hash[0, 1]])",
+          "\n      LogicalProject(col1=[$0], col2=[$1], col3=[$2])",
+          "\n        LogicalFilter(condition=[AND(>=($2, 0), =($0, 'a'))])",
+          "\n          LogicalTableScan(table=[[a]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "aggregate with skip leaf stage hint, group by 
aggregate with having clause",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ skipLeafStageGroupByAggregation */ 
a.col2, COUNT(*), SUM(a.col3), SUM(a.col1) FROM a WHERE a.col3 >= 0 AND a.col2 
= 'a' GROUP BY a.col2 HAVING COUNT(*) > 10 AND MAX(a.col3) >= 0 AND MIN(a.col3) 
< 20 AND SUM(a.col3) <= 10 AND AVG(a.col3) = 5",
+        "output": [
+          "Execution Plan",
+          "\nLogicalProject(col2=[$0], EXPR$1=[$1], EXPR$2=[$2], EXPR$3=[$3])",
+          "\n  LogicalFilter(condition=[AND(>($1, 10), >=($4, 0), <($5, 20), 
<=($2, 10), =(/(CAST($2):DOUBLE NOT NULL, $1), 5))])",
+          "\n    LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], 
EXPR$2=[$SUM0($1)], EXPR$3=[$SUM0($2)], agg#3=[MAX($1)], agg#4=[MIN($1)])",
+          "\n      LogicalExchange(distribution=[hash[0]])",
+          "\n        LogicalProject(col2=[$1], col3=[$2], 
$f2=[CAST($0):DECIMAL(1000, 500) NOT NULL])",
+          "\n          LogicalFilter(condition=[AND(>=($2, 0), =($1, 'a'))])",
+          "\n            LogicalTableScan(table=[[a]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "aggregate with skip intermediate stage hint (via 
hinting the leaf stage group by as final stage_",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ aggFinalStage */ a.col2, COUNT(*), 
SUM(a.col3), SUM(a.col1) FROM a WHERE a.col3 >= 0 AND a.col2 = 'a' GROUP BY 
a.col2 HAVING COUNT(*) > 10",
+        "output": [
+          "Execution Plan",
+          "\nLogicalFilter(condition=[>($1, 10)])",
+          "\n  LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], 
EXPR$2=[$SUM0($1)], EXPR$3=[$SUM0($2)])",
+          "\n    LogicalProject(col2=[$1], col3=[$2], 
$f2=[CAST($0):DECIMAL(1000, 500) NOT NULL])",
+          "\n      LogicalFilter(condition=[AND(>=($2, 0), =($1, 'a'))])",
+          "\n        LogicalTableScan(table=[[a]])",
+          "\n"
+        ]
+      },
+      {
+        "description": "aggregate with skip leaf stage hint (via hint option 
partitioned_by_group_by_keys",
+        "sql": "EXPLAIN PLAN FOR SELECT /*+ 
aggOptions(partitioned_by_group_by_keys='true') */ a.col2, COUNT(*), 
SUM(a.col3), SUM(a.col1) FROM a WHERE a.col3 >= 0 AND a.col2 = 'a' GROUP BY 
a.col2",
+        "output": [
+          "Execution Plan",
+          "\nLogicalAggregate(group=[{0}], EXPR$1=[COUNT()], 
EXPR$2=[$SUM0($1)], EXPR$3=[$SUM0($2)])",
+          "\n  LogicalProject(col2=[$1], col3=[$2], 
$f2=[CAST($0):DECIMAL(1000, 500) NOT NULL])",
+          "\n    LogicalFilter(condition=[AND(>=($2, 0), =($1, 'a'))])",
+          "\n      LogicalTableScan(table=[[a]])",
+          "\n"
+        ]
+      }
+    ]
+  }
+}

Review Comment:
   nit: newline



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/rules/PinotAggregateExchangeNodeInsertRule.java:
##########
@@ -88,8 +92,11 @@ public boolean matches(RelOptRuleCall call) {
     }
     if (call.rel(0) instanceof Aggregate) {
       Aggregate agg = call.rel(0);
-      return !agg.getHints().contains(AggregateNode.INTERMEDIATE_STAGE_HINT)
-          && !agg.getHints().contains(AggregateNode.FINAL_STAGE_HINT);
+      ImmutableList<RelHint> hints = agg.getHints();
+      return !PinotHintStrategyTable.containsHint(hints, 
PinotHintStrategyTable.INTERNAL_AGG_INTERMEDIATE_STAGE)
+          && !PinotHintStrategyTable.containsHint(hints, 
PinotHintStrategyTable.INTERNAL_AGG_FINAL_STAGE)
+          && !PinotHintStrategyTable.containsHintOption(hints, 
PinotHintOptions.AGGREGATE_HINT_OPTIONS,
+          PinotHintOptions.AggregateOptions.IS_PARTITIONED_BY_GROUP_BY_KEYS);

Review Comment:
   what if user put a hint of `IS_PARTITIONED_BY_GROUP_BY_KEYS` but put value 
`false`?
   



##########
pinot-query-planner/src/main/java/org/apache/calcite/rel/hint/PinotHintOptions.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.hint;
+
+/**
+ * {@code PinotHintOptions} specified the supported hint options by Pinot 
based a particular type of relation node.
+ *
+ * <p>for each {@link org.apache.calcite.rel.RelNode} type we support a option 
hint name.</p>
+ * <p>for each option hint name there's a corresponding {@link RelHint} that 
supported only key-value option stored
+ * in {@link RelHint#kvOptions}</p>
+ */
+public class PinotHintOptions {
+  public static final String AGGREGATE_HINT_OPTIONS = "aggOptions";
+  public static final String JOIN_HINT_OPTIONS = "joinOptions";
+
+  private PinotHintOptions() {
+    // do not instantiate.
+  }
+
+  public static class AggregateOptions {
+    public static final String IS_PARTITIONED_BY_GROUP_BY_KEYS = 
"partitioned_by_group_by_keys";
+  }
+
+  public static class JoinHintOptions {
+    public static final String JOIN_STRATEGY = "join_strategy";
+    public static final String IS_COLOCATED_BY_JOIN_KEYS = 
"colocated_by_join_keys";

Review Comment:
   `is_colocated_by_join_keys`



-- 
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-unsubscr...@pinot.apache.org

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


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

Reply via email to