AngersZhuuuu commented on a change in pull request #26437: [SPARK-29800][SQL] 
Plan non-correlated Exists 's subquery in PlanSubqueries
URL: https://github.com/apache/spark/pull/26437#discussion_r345585182
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/subquery.scala
 ##########
 @@ -171,6 +173,57 @@ case class InSubqueryExec(
   }
 }
 
+/**
+ * The physical node of non-correlated EXISTS subquery.
+ */
+case class ExistsExec(
+    plan: BaseSubqueryExec,
+    exprId: ExprId)
+  extends ExecSubqueryExpression {
+
+  @transient private var result: Boolean = _
+
+  override def dataType: DataType = BooleanType
+  override def children: Seq[Expression] = Nil
+  override def nullable: Boolean = false
+  override def toString: String = s"EXISTS 
(${plan.simpleString(SQLConf.get.maxToStringFields)})"
+  override def withNewPlan(plan: BaseSubqueryExec): ExistsExec = copy(plan = 
plan)
+
+  override def semanticEquals(other: Expression): Boolean = other match {
+    case in: ExistsExec => plan.sameResult(in.plan)
+    case _ => false
+  }
+
+  def updateResult(): Unit = {
+    result = plan.executeTake(1).length == 1
+  }
+
+  def values(): Option[Boolean] = Option(result)
+
+  override def eval(input: InternalRow): Any = {
+    result
+  }
+
+  override lazy val canonicalized: ExistsExec = {
+    copy(
+      plan = plan.canonicalized.asInstanceOf[BaseSubqueryExec],
+      exprId = ExprId(0))
+  }
+
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
 
 Review comment:
   > again, can we follow `org.apache.spark.sql.execution.ScalarSubquery`? The 
codegen is well implemented there.
   
   Done

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to