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

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

                Author: ASF GitHub Bot
            Created on: 02/Jul/19 16:40
            Start Date: 02/Jul/19 16:40
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on pull request #693: HIVE-21921: 
Support for correlated quantified predicates
URL: https://github.com/apache/hive/pull/693#discussion_r299576240
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSubQueryRemoveRule.java
 ##########
 @@ -230,33 +228,59 @@ private RexNode rewriteScalar(RelMetadataQuery mq, 
RexSubQuery e, Set<Correlatio
   private RexNode rewriteSomeAll(RexSubQuery e, Set<CorrelationId> 
variablesSet,
       HiveSubQRemoveRelBuilder builder) {
     final SqlQuantifyOperator op = (SqlQuantifyOperator) e.op;
-    assert(op == SqlStdOperatorTable.SOME_GE
-        || op == SqlStdOperatorTable.SOME_LE
-        || op == SqlStdOperatorTable.SOME_LT
-        || op == SqlStdOperatorTable.SOME_GT);
-    builder.push(e.rel)
-        .aggregate(builder.groupKey(),
-            op.comparisonKind == SqlKind.GREATER_THAN
-                || op.comparisonKind == SqlKind.GREATER_THAN_OR_EQUAL
-                ? builder.min("m", builder.field(0))
-                : builder.max("m", builder.field(0)),
-            builder.count(false, "c"),
-            builder.count(false, "d", builder.field(0)))
-        .as("q")
-        .join(JoinRelType.INNER);
-    return builder.call(SqlStdOperatorTable.CASE,
-        builder.call(SqlStdOperatorTable.EQUALS,
-            builder.field("q", "c"), builder.literal(0)),
-        builder.literal(false),
-        builder.call(SqlStdOperatorTable.IS_TRUE,
-            builder.call(RelOptUtil.op(op.comparisonKind, null),
-                e.operands.get(0), builder.field("q", "m"))),
-        builder.literal(true),
-        builder.call(SqlStdOperatorTable.GREATER_THAN,
-            builder.field("q", "c"), builder.field("q", "d")),
-        
e.rel.getCluster().getRexBuilder().makeNullLiteral(SqlTypeName.BOOLEAN),
-        builder.call(RelOptUtil.op(op.comparisonKind, null),
-            e.operands.get(0), builder.field("q", "m")));
+    assert (op == SqlStdOperatorTable.SOME_GE || op == 
SqlStdOperatorTable.SOME_LE
+        || op == SqlStdOperatorTable.SOME_LT || op == 
SqlStdOperatorTable.SOME_GT);
+    if (variablesSet.isEmpty()) {
+      builder.push(e.rel)
+          .aggregate(builder.groupKey(),
+              op.comparisonKind == SqlKind.GREATER_THAN
+                  || op.comparisonKind == SqlKind.GREATER_THAN_OR_EQUAL
+                  ? builder.min("m", builder.field(0))
+                  : builder.max("m", builder.field(0)),
+              builder.count(false, "c"),
+              builder.count(false, "d", builder.field(0)))
+          .as("q")
+          .join(JoinRelType.INNER);
+      return builder.call(SqlStdOperatorTable.CASE,
+          builder.call(SqlStdOperatorTable.EQUALS,
+              builder.field("q", "c"), builder.literal(0)),
 
 Review comment:
   I think we should use positions to create the field references since I am 
not sure how much we can rely on aliases. For instance, what would happen if 
there is a group key with an alias 'c'? Wouldn't that cause a collision with 
the name for the count column?
 
----------------------------------------------------------------
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: 271021)
    Time Spent: 40m  (was: 0.5h)

> Support for correlated quantified predicates
> --------------------------------------------
>
>                 Key: HIVE-21921
>                 URL: https://issues.apache.org/jira/browse/HIVE-21921
>             Project: Hive
>          Issue Type: New Feature
>          Components: Query Planning
>            Reporter: Vineet Garg
>            Assignee: Vineet Garg
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-21921.1.patch, HIVE-21921.2.patch, 
> HIVE-21921.3.patch, HIVE-21921.4.patch
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to