zabetak commented on code in PR #5249:
URL: https://github.com/apache/hive/pull/5249#discussion_r1671902459


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TableScanToSpoolRule.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptMaterialization;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.prepare.RelOptTableImpl;
+import org.apache.calcite.rel.core.Spool;
+import org.apache.calcite.rel.core.TableScan;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static 
org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories.HIVE_SPOOL_FACTORY;
+
+public class TableScanToSpoolRule extends RelOptRule {
+  /**
+   * Track created spools to avoid introducing more than one.
+   */
+  private final Set<String> spools = new HashSet<>();
+  private final int referenceThreshold;
+  private final Map<List<String>, Long> tableOccurrences;
+  public TableScanToSpoolRule(Map<List<String>, Long> tableOccurrences, int 
referenceThreshold) {
+    super(operand(TableScan.class, none()));
+    this.referenceThreshold = referenceThreshold;
+    this.tableOccurrences = tableOccurrences;
+    assert referenceThreshold > 0;

Review Comment:
   The Spool will be introduced (resp. CTE will be materialized) when 
`tableOccurences > referenceThreshold` (the condition is evaluated in the 
`matches` method) thus `referenceThershold = 1` is a perfectly legal value and 
it means "more than 1 references".



-- 
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: gitbox-unsubscr...@hive.apache.org

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


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

Reply via email to