mgaido91 commented on a change in pull request #23531: [SPARK-24497][SQL] 
Support recursive SQL query
URL: https://github.com/apache/spark/pull/23531#discussion_r247441697
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
 ##########
 @@ -47,6 +48,41 @@ case class Subquery(child: LogicalPlan) extends 
OrderPreservingUnaryNode {
   override def output: Seq[Attribute] = child.output
 }
 
+case class RecursiveTable(
+    name: String,
+    anchorTerm: LogicalPlan,
+    recursiveTerm: LogicalPlan,
+    levelLimit: Int) extends LogicalPlan {
+  override def children: Seq[LogicalPlan] = Seq(anchorTerm, recursiveTerm)
+
+  override def output: Seq[Attribute] = 
anchorTerm.output.map(_.withNullability(true))
+
+  override lazy val resolved: Boolean = {
+    val numberOfOutputMatches =
+      childrenResolved &&
+      anchorTerm.output.length > 0 &&
+      anchorTerm.output.length == recursiveTerm.output.length
+    if (numberOfOutputMatches) {
+      val typeOfOutputMatches = 
anchorTerm.output.zip(recursiveTerm.output).forall {
+        case (l, r) => l.dataType.sameType(r.dataType)
+      }
+      if (!typeOfOutputMatches) {
+        throw new AnalysisException(s"Anchor term types 
${anchorTerm.output.map(_.dataType)} " +
+          s"and recursive term types ${recursiveTerm.output.map(_.dataType)} 
doesn't match")
+      }
+    }
+    numberOfOutputMatches
+  }
+
+  lazy val anchorResolved = anchorTerm.resolved
+}
+
+case class RecursiveReference(name: String, output: Seq[Attribute]) extends 
LeafNode {
+  override lazy val resolved = true
 
 Review comment:
   I think this should be `output.forall(_.resolved)`. I see that you think 
you'll put here only resolved attributes, but error conditions may happen (now 
or in the future) and in this way we care safer IMHO.

----------------------------------------------------------------
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