francis0407 commented on a change in pull request #23783: [SPARK-26854][SQL] 
Support ANY/SOME subquery
URL: https://github.com/apache/spark/pull/23783#discussion_r257452132
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -1148,6 +1165,12 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
         EqualNullSafe(e, expression(ctx.right))
       case SqlBaseParser.DISTINCT =>
         Not(EqualNullSafe(e, expression(ctx.right)))
+      case SqlBaseParser.ANY | SqlBaseParser.SOME =>
+        invertIfNotDefined(AnySubquery(
+            getValueExpressions(e),
+            getComparisonOperator(
+              
ctx.comparisonOperator.getChild(0).asInstanceOf[TerminalNode].getSymbol.getType),
+            ListQuery(plan(ctx.query))))
 
 Review comment:
   Hi, I found another problem during revision. 
   If we use `AnySubquery(cmp: BinaryComparison)`, `left` inside the `cmp` is 
an `Expression` instead of `Seq[Expression]`, which can not be analyzed by the 
rule `ResolveReferences`(since it uses `mapProductIterator`). 
   Therefore, I have to define it as 
   ```scala
   case class AnySubquery(values: Seq[Expression], cmp: BinaryComparison, 
query: ListQuery)
   ```
   and define another apply function as 
   ```scala
   object AnySubqury {
     def apply(cmp: BinaryComparison): AnySubquery = ...
   }
   ```
   As a result, this becomes more and more unnatural.
   
   I am wondering if it is necessary to restrict the type of `comparison` as 
`BinaryComparison`. If it is not, then we won't need `NotEqualTo()` any more 
and we can define `AnySubquery` as 
   ```scala
   case class AnySubquery(values: Seq[Expression], comparison: (Expression, 
Expression) => Expression, query: ListQuery)
   ```
   There is no need to rewrite `comparison` either. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to