Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ abstract class TypeCoercionBase extends TypeCoercionHelper {
case (attr, dt) =>
val widerType = findWiderTypeForTwo(attr.dataType, dt)
if (widerType.isDefined && widerType.get == dt) {
Alias(Cast(attr, dt), attr.name)()
if (attr.dataType != dt) {
Alias(Cast(attr, dt), attr.name)()
} else {
attr
}
} else {
throw cannotMergeIncompatibleDataTypesError(dt, attr.dataType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ WithCTE
: +- UnionLoop xxxx
: :- Project [1 AS 1#x, cast(1 as bigint) AS CAST(1 AS BIGINT)#xL]
: : +- OneRowRelation
: +- Project [cast((n + 1)#x as int) AS (n + 1)#x, cast((n + 1)#x as bigint) AS (n + 1)#xL]
: +- Project [(n + 1)#x, cast((n + 1)#x as bigint) AS (n + 1)#xL]
: +- Project [(n#x + 1) AS (n + 1)#x, (n#x + 1) AS (n + 1)#x]
: +- Filter (n#x < 5)
: +- SubqueryAlias t1
Expand Down Expand Up @@ -1936,6 +1936,32 @@ org.apache.spark.SparkException
}


-- !query
WITH RECURSIVE t1(n, str, ts) AS (
SELECT 1, '2024-01-15 00:00:00' ,CAST('2024-01-15 00:00:00' AS TIMESTAMP)
UNION ALL
SELECT n + 1, str, str FROM t1 WHERE n < 5
)
SELECT * FROM t1
-- !query analysis
WithCTE
:- CTERelationDef xxxx, false
: +- SubqueryAlias t1
: +- Project [1#x AS n#x, 2024-01-15 00:00:00#x AS str#x, CAST(2024-01-15 00:00:00 AS TIMESTAMP)#x AS ts#x]
: +- UnionLoop xxxx
: :- Project [1 AS 1#x, 2024-01-15 00:00:00 AS 2024-01-15 00:00:00#x, cast(2024-01-15 00:00:00 as timestamp) AS CAST(2024-01-15 00:00:00 AS TIMESTAMP)#x]
: : +- OneRowRelation
: +- Project [(n + 1)#x, str#x, cast(str#x as timestamp) AS str#x]
: +- Project [(n#x + 1) AS (n + 1)#x, str#x, str#x]
: +- Filter (n#x < 5)
: +- SubqueryAlias t1
: +- Project [1#x AS n#x, 2024-01-15 00:00:00#x AS str#x, CAST(2024-01-15 00:00:00 AS TIMESTAMP)#x AS ts#x]
: +- UnionLoopRef xxxx, [1#x, 2024-01-15 00:00:00#x, CAST(2024-01-15 00:00:00 AS TIMESTAMP)#x], false
+- Project [n#x, str#x, ts#x]
+- SubqueryAlias t1
+- CTERelationRef xxxx, true, [n#x, str#x, ts#x], false, false


-- !query
WITH RECURSIVE t1(n) AS (
SELECT 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ WITH RECURSIVE t1(n, m) AS (
SELECT n+1, CAST(n+1 AS BIGINT) FROM t1 WHERE n < 5)
SELECT * FROM t1;

-- Type coercion with timeZone sensitive type
WITH RECURSIVE t1(n, str, ts) AS (
SELECT 1, '2024-01-15 00:00:00' ,CAST('2024-01-15 00:00:00' AS TIMESTAMP)
UNION ALL
SELECT n + 1, str, str FROM t1 WHERE n < 5
)
SELECT * FROM t1;

-- Recursive CTE with nullable recursion and non-recursive anchor
WITH RECURSIVE t1(n) AS (
SELECT 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,23 @@ org.apache.spark.SparkException
}


-- !query
WITH RECURSIVE t1(n, str, ts) AS (
SELECT 1, '2024-01-15 00:00:00' ,CAST('2024-01-15 00:00:00' AS TIMESTAMP)
UNION ALL
SELECT n + 1, str, str FROM t1 WHERE n < 5
)
SELECT * FROM t1
-- !query schema
struct<n:int,str:string,ts:timestamp>
-- !query output
1 2024-01-15 00:00:00 2024-01-15 00:00:00
2 2024-01-15 00:00:00 2024-01-15 00:00:00
3 2024-01-15 00:00:00 2024-01-15 00:00:00
4 2024-01-15 00:00:00 2024-01-15 00:00:00
5 2024-01-15 00:00:00 2024-01-15 00:00:00


-- !query
WITH RECURSIVE t1(n) AS (
SELECT 1
Expand Down