[ 
https://issues.apache.org/jira/browse/HIVE-23389?focusedWorklogId=432464&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-432464
 ]

ASF GitHub Bot logged work on HIVE-23389:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/May/20 01:22
            Start Date: 10/May/20 01:22
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on a change in pull request #1010:
URL: https://github.com/apache/hive/pull/1010#discussion_r422568569



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveFilterMergeRule.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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 java.util.List;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexLocalRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.Bug;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter;
+
+/**
+ * Mostly a copy of {@link org.apache.calcite.rel.rules.FilterMergeRule}.
+ * However, it flattens the predicate before creating the new filter.
+ */
+public class HiveFilterMergeRule extends RelOptRule {
+
+  public static final HiveFilterMergeRule INSTANCE =
+      new HiveFilterMergeRule();
+
+  /** Private constructor. */
+  private HiveFilterMergeRule() {
+    super(operand(HiveFilter.class,
+        operand(HiveFilter.class, any())),
+        HiveRelFactories.HIVE_BUILDER, null);
+    if (Bug.CALCITE_3982_FIXED) {
+      throw new AssertionError("Remove logic in HiveFilterMergeRule when 
[CALCITE-3982] "
+          + "has been fixed and use directly Calcite's FilterMergeRule 
instead.");
+    }
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  public void onMatch(RelOptRuleCall call) {
+    final HiveFilter topFilter = call.rel(0);
+    final HiveFilter bottomFilter = call.rel(1);
+
+    RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
+    RexProgram bottomProgram = createProgram(bottomFilter);
+    RexProgram topProgram = createProgram(topFilter);
+
+    RexProgram mergedProgram =
+        RexProgramBuilder.mergePrograms(
+            topProgram,
+            bottomProgram,
+            rexBuilder);
+
+    RexNode newCondition = expandLocalRef(rexBuilder,
+        mergedProgram.getCondition(), mergedProgram.getExprList());
+
+    final RelBuilder relBuilder = call.builder();
+    relBuilder.push(bottomFilter.getInput())
+        .filter(newCondition);

Review comment:
       You are right... I copied the code as-is from Calcite but I think going 
through the program is actually not necessary.




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 432464)
    Time Spent: 0.5h  (was: 20m)

> FilterMergeRule can lead to AssertionError
> ------------------------------------------
>
>                 Key: HIVE-23389
>                 URL: https://issues.apache.org/jira/browse/HIVE-23389
>             Project: Hive
>          Issue Type: Bug
>          Components: CBO
>            Reporter: Jesus Camacho Rodriguez
>            Assignee: Jesus Camacho Rodriguez
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-23389.01.patch, HIVE-23389.01.patch, 
> HIVE-23389.02.patch, HIVE-23389.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> I have not been able to reproduce the issue in latest master. However, this 
> could potentially happen since Filter creation has a check on whether the 
> expression is flat 
> ([here|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/core/Filter.java#L74])
>  and Filter merge does not flatten an expression when it is created.
> {noformat}
> java.lang.AssertionError: AND(=($3, 100), OR(OR(null, IS NOT 
> NULL(CAST(100):INTEGER)), =(CAST(100):INTEGER, CAST(200):INTEGER)))
>       at org.apache.calcite.rel.core.Filter.<init>(Filter.java:74)
>       at 
> org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter.<init>(HiveFilter.java:39)
>       at 
> org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories$HiveFilterFactoryImpl.createFilter(HiveRelFactories.java:126)
>       at 
> org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelBuilder.filter(HiveRelBuilder.java:99)
>       at org.apache.calcite.tools.RelBuilder.filter(RelBuilder.java:1055)
>       at 
> org.apache.calcite.rel.rules.FilterMergeRule.onMatch(FilterMergeRule.java:81)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to