Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-16689

Correlated scalar subquery with comparison to constant in predicate fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0
    • None
    • None

    Description

      Reproducer

      CREATE TABLE `item`(
        `i_item_sk` int,
        `i_item_id` char(16),
        `i_rec_start_date` date,
        `i_rec_end_date` date,
        `i_item_desc` varchar(200),
        `i_current_price` decimal(7,2),
        `i_wholesale_cost` decimal(7,2),
        `i_brand_id` int,
        `i_brand` char(50),
        `i_class_id` int,
        `i_class` char(50),
        `i_category_id` int,
        `i_category` char(50),
        `i_manufact_id` int,
        `i_manufact` char(50),
        `i_size` char(20),
        `i_formulation` char(20),
        `i_color` char(20),
        `i_units` char(10),
        `i_container` char(10),
        `i_manager_id` int,
        `i_product_name` char(50));
      
      select count(*)
       from item i1
       where
         (select count(*)
             from item
             where (i_manufact = i1.i_manufact)) > 0;
      

      Error stack

      org.apache.calcite.util.mapping.Mappings$NoElementException: source #0 has no target in mapping [size=0, sourceCount=1, targetCount=1, elements=[]]
      	at org.apache.calcite.util.mapping.Mappings$AbstractMapping.getTarget(Mappings.java:874) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.RelFieldTrimmer$2.handle(RelFieldTrimmer.java:304) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder$MyRexVisitor.visitFieldAccess(CorrelationReferenceFinder.java:59) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder$MyRexVisitor.visitFieldAccess(CorrelationReferenceFinder.java:50) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexFieldAccess.accept(RexFieldAccess.java:81) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:148) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:97) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:36) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexCall.accept(RexCall.java:104) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:279) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.core.Filter.accept(Filter.java:103) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder.visit(CorrelationReferenceFinder.java:44) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter.accept(HiveFilter.java:116) ~[hive-exec-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:55) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:69) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:131) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder.visit(CorrelationReferenceFinder.java:43) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject.accept(HiveProject.java:198) ~[hive-exec-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:55) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:69) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:131) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder.visit(CorrelationReferenceFinder.java:43) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:279) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:55) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:69) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:131) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder.visit(CorrelationReferenceFinder.java:43) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject.accept(HiveProject.java:198) ~[hive-exec-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder$MyRexVisitor.visitSubQuery(CorrelationReferenceFinder.java:65) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder$MyRexVisitor.visitSubQuery(CorrelationReferenceFinder.java:50) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexSubQuery.accept(RexSubQuery.java:85) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:148) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:97) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:36) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexCall.accept(RexCall.java:104) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:279) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.rel.core.Filter.accept(Filter.java:103) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.CorrelationReferenceFinder.visit(CorrelationReferenceFinder.java:44) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter.accept(HiveFilter.java:116) ~[hive-exec-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
      	at org.apache.calcite.sql2rel.RelFieldTrimmer.result(RelFieldTrimmer.java:296) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.RelFieldTrimmer.dummyProject(RelFieldTrimmer.java:434) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:390) ~[calcite-core-1.12.0.jar:1.12.0]
      	at org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveRelFieldTrimmer.trimFields(HiveRelFieldTrimmer.java:273) ~[hive-exec-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]
      	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]
      	at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:525) ~[calcite-core-1.12.0.jar:1.12.0]
      

      Attachments

        1. HIVE-16689.1.patch
          10 kB
          Vineet Garg
        2. HIVE-16689.2.patch
          9 kB
          Vineet Garg

        Activity

          People

            vgarg Vineet Garg
            vgarg Vineet Garg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: