Skip to content
Open
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 @@ -2725,8 +2725,14 @@ class AstBuilder extends DataTypeAstBuilder
// inline table comes in two styles:
// style 1: values (1), (2), (3) -- multiple columns are supported
// style 2: values 1, 2, 3 -- only a single column is supported here
case struct: CreateNamedStruct => struct.valExprs // style 1
case child => Seq(child) // style 2
// Strip Alias wrappers from row values — CreateStruct.apply preserves them for
// expressions like `(1 AS id, 'a' AS name)`, but they are redundant here since
// column names are determined by the table alias or generated defaults.
case struct: CreateNamedStruct => struct.valExprs.map {
case a: Alias => a.child
case other => other
} // style 1
case child => Seq(child) // style 2
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,24 @@ select count(distinct ct) from values now(), now(), now() as data(ct)
select count(distinct ct) from values current_timestamp(), current_timestamp() as data(ct)
-- !query analysis
[Analyzer test output redacted due to nondeterminism]


-- !query
select a from (values (1 as id, current_timestamp() as ts), (2 as id, current_timestamp() as ts)) as t(a, b)
-- !query analysis
[Analyzer test output redacted due to nondeterminism]


-- !query
select * from values (1 as id, 'a' as name), (2 as id, 'b' as name) as t(a, b)
-- !query analysis
Project [a#x, b#x]
+- SubqueryAlias t
+- LocalRelation [a#x, b#x]


-- !query
select * from values (1 as a, 2 as b)
-- !query analysis
Project [col1#x, col2#x]
+- LocalRelation [col1#x, col2#x]
9 changes: 9 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/inline-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ select count(distinct ct) from values now(), now(), now() as data(ct);

-- current_timestamp() should be kept as tempResolved inline expression.
select count(distinct ct) from values current_timestamp(), current_timestamp() as data(ct);

-- aliased expressions in multi-column rows with current_timestamp (non-foldable)
select a from (values (1 as id, current_timestamp() as ts), (2 as id, current_timestamp() as ts)) as t(a, b);

-- aliased expressions in multi-column rows
select * from values (1 as id, 'a' as name), (2 as id, 'b' as name) as t(a, b);

-- aliased expressions without table alias
select * from values (1 as a, 2 as b);
26 changes: 26 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/inline-table.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,29 @@ select count(distinct ct) from values current_timestamp(), current_timestamp() a
struct<count(DISTINCT ct):bigint>
-- !query output
1


-- !query
select a from (values (1 as id, current_timestamp() as ts), (2 as id, current_timestamp() as ts)) as t(a, b)
-- !query schema
struct<a:int>
-- !query output
1
2


-- !query
select * from values (1 as id, 'a' as name), (2 as id, 'b' as name) as t(a, b)
-- !query schema
struct<a:int,b:string>
-- !query output
1 a
2 b


-- !query
select * from values (1 as a, 2 as b)
-- !query schema
struct<col1:int,col2:int>
-- !query output
1 2