aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/resources/sql-tests/results/struct.sql.out
diff options
context:
space:
mode:
authorHerman van Hovell <hvanhovell@databricks.com>2017-03-14 12:49:30 +0100
committerHerman van Hovell <hvanhovell@databricks.com>2017-03-14 12:49:30 +0100
commita0b92f73fed9b91883f08cced1c09724e09e1883 (patch)
tree4fbefa883457a54800e4f25a752b259028b045ba /sql/core/src/test/resources/sql-tests/results/struct.sql.out
parent0ee38a39e43dd7ad9d50457e446ae36f64621a1b (diff)
downloadspark-a0b92f73fed9b91883f08cced1c09724e09e1883.tar.gz
spark-a0b92f73fed9b91883f08cced1c09724e09e1883.tar.bz2
spark-a0b92f73fed9b91883f08cced1c09724e09e1883.zip
[SPARK-19850][SQL] Allow the use of aliases in SQL function calls
## What changes were proposed in this pull request? We currently cannot use aliases in SQL function calls. This is inconvenient when you try to create a struct. This SQL query for example `select struct(1, 2) st`, will create a struct with column names `col1` and `col2`. This is even more problematic when we want to append a field to an existing struct. For example if we want to a field to struct `st` we would issue the following SQL query `select struct(st.*, 1) as st from src`, the result will be struct `st` with an a column with a non descriptive name `col3` (if `st` itself has 2 fields). This PR proposes to change this by allowing the use of aliased expression in function parameters. For example `select struct(1 as a, 2 as b) st`, will create a struct with columns `a` & `b`. ## How was this patch tested? Added a test to `ExpressionParserSuite` and added a test file for `SQLQueryTestSuite`. Author: Herman van Hovell <hvanhovell@databricks.com> Closes #17245 from hvanhovell/SPARK-19850.
Diffstat (limited to 'sql/core/src/test/resources/sql-tests/results/struct.sql.out')
-rw-r--r--sql/core/src/test/resources/sql-tests/results/struct.sql.out60
1 files changed, 60 insertions, 0 deletions
diff --git a/sql/core/src/test/resources/sql-tests/results/struct.sql.out b/sql/core/src/test/resources/sql-tests/results/struct.sql.out
new file mode 100644
index 0000000000..3e32f46195
--- /dev/null
+++ b/sql/core/src/test/resources/sql-tests/results/struct.sql.out
@@ -0,0 +1,60 @@
+-- Automatically generated by SQLQueryTestSuite
+-- Number of queries: 6
+
+
+-- !query 0
+CREATE TEMPORARY VIEW tbl_x AS VALUES
+ (1, NAMED_STRUCT('C', 'gamma', 'D', 'delta')),
+ (2, NAMED_STRUCT('C', 'epsilon', 'D', 'eta')),
+ (3, NAMED_STRUCT('C', 'theta', 'D', 'iota'))
+ AS T(ID, ST)
+-- !query 0 schema
+struct<>
+-- !query 0 output
+
+
+
+-- !query 1
+SELECT STRUCT('alpha', 'beta') ST
+-- !query 1 schema
+struct<ST:struct<col1:string,col2:string>>
+-- !query 1 output
+{"col1":"alpha","col2":"beta"}
+
+
+-- !query 2
+SELECT STRUCT('alpha' AS A, 'beta' AS B) ST
+-- !query 2 schema
+struct<ST:struct<A:string,B:string>>
+-- !query 2 output
+{"A":"alpha","B":"beta"}
+
+
+-- !query 3
+SELECT ID, STRUCT(ST.*) NST FROM tbl_x
+-- !query 3 schema
+struct<ID:int,NST:struct<C:string,D:string>>
+-- !query 3 output
+1 {"C":"gamma","D":"delta"}
+2 {"C":"epsilon","D":"eta"}
+3 {"C":"theta","D":"iota"}
+
+
+-- !query 4
+SELECT ID, STRUCT(ST.*,CAST(ID AS STRING) AS E) NST FROM tbl_x
+-- !query 4 schema
+struct<ID:int,NST:struct<C:string,D:string,E:string>>
+-- !query 4 output
+1 {"C":"gamma","D":"delta","E":"1"}
+2 {"C":"epsilon","D":"eta","E":"2"}
+3 {"C":"theta","D":"iota","E":"3"}
+
+
+-- !query 5
+SELECT ID, STRUCT(CAST(ID AS STRING) AS AA, ST.*) NST FROM tbl_x
+-- !query 5 schema
+struct<ID:int,NST:struct<AA:string,C:string,D:string>>
+-- !query 5 output
+1 {"AA":"1","C":"gamma","D":"delta"}
+2 {"AA":"2","C":"epsilon","D":"eta"}
+3 {"AA":"3","C":"theta","D":"iota"}