Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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,16 @@ org.apache.spark.SparkException
}


-- !query
WITH RECURSIVE t1(n, stamp) AS (
SELECT 1, CAST(DATE '2024-01-15' AS TIMESTAMP)
UNION ALL
SELECT n+1, stamp FROM t1 WHERE n < 5)
SELECT * FROM t1
-- !query analysis
[Analyzer test output redacted due to nondeterminism]
Copy link
Contributor

@peter-toth peter-toth Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this non-deterministic? If it is really non-deterministic, can you add a deterministic test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was nondeterministic because the original relation was Date. I changed into string now.
It's deterministic now.



-- !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,13 @@ 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, stamp) AS (
SELECT 1, CAST(DATE '2024-01-15' AS TIMESTAMP)
UNION ALL
SELECT n+1, stamp 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,22 @@ org.apache.spark.SparkException
}


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


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