milanisvet commented on code in PR #49518: URL: https://github.com/apache/spark/pull/49518#discussion_r1925279434
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveWithCTE.scala: ########## @@ -183,4 +184,52 @@ object ResolveWithCTE extends Rule[LogicalPlan] { columnNames.map(UnresolvedSubqueryColumnAliases(_, ref)).getOrElse(ref) } } + + /** + * Checks if data types of anchor and recursive terms of a recursive CTE definition match. + */ + def checkDataTypesAnchorAndRecursiveTerm(unionLoop: UnionLoop): Unit = { + val anchorOutputDatatypes = unionLoop.anchor.output.map(_.dataType) + val recursiveTermOutputDatatypes = unionLoop.recursion.output.map(_.dataType) + + if (!anchorOutputDatatypes.zip(recursiveTermOutputDatatypes).forall { + case (anchorDT, recursionDT) => DataType.equalsStructurally(anchorDT, recursionDT, true) Review Comment: Rewritten, but I might completely remove data type checking as I realized that we might end up in some unexpected behavior. ``` WITH RECURSIVE r(level, data) AS ( VALUES (0, 0) UNION ALL SELECT level + 1, r.data FROM r WHERE r.level < 9 ) SELECT * FROM r ``` This query will throw data type error although it should not. The queries for which data type error should indeed be thrown should end up anyway in `[CANNOT_MERGE_INCOMPATIBLE_DATA_TYPE]`. I will try with more examples to confirm this -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org