You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/05/24 21:13:45 UTC

[GitHub] [hive] jcamachor commented on a change in pull request #2302: [HIVE-25090] Join condition parsing error in subquery

jcamachor commented on a change in pull request #2302:
URL: https://github.com/apache/hive/pull/2302#discussion_r638272749



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveJoinExtractFilterRule.java
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.tools.RelBuilderFactory;
+
+public class HiveJoinExtractFilterRule extends RelOptRule {
+  public HiveJoinExtractFilterRule(Class<? extends Join> clazz,
+                                   RelBuilderFactory relBuilderFactory) {
+    super(operand(clazz, any()), relBuilderFactory, null);
+  }
+
+  @Override
+  public void onMatch(RelOptRuleCall call) {
+    final Join join = call.rel(0);

Review comment:
       Shouldn't you check the type of join? If this is a (left/right/full) outer join, JOIN with condition will not be equivalent to cartesian product with a filter with the same condition on top. In SQL:
   ```
   p1 LEFT OUTER JOIN p2 ON (p1.a = p2.b) != p1 LEFT OUTER JOIN p2 WHERE (p1.a = p2.b)
   ```

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveFilter.java
##########
@@ -103,9 +104,11 @@ private static void traverseFilter(RexNode node, Set<CorrelationId> allVars) {
           RelNode input = ((RexSubQuery)node).rel.getInput(0);
           while(input != null && !(input instanceof HiveFilter)
                   && input.getInputs().size() >=1) {
-              //we don't expect corr vars withing JOIN or UNION for now
-              // we only expect cor vars in top level filter
+              //we don't expect corr vars within UNION for now
               if(input.getInputs().size() > 1) {
+                if (input instanceof HiveJoin) {
+                  findCorrelatedVar(((HiveJoin) input).getJoinFilter(), allVars);
+                }
                   return;

Review comment:
       nit. fix indentation




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

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



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