Commit ea222a3
[SPARK-49566][SQL] Add SQL pipe syntax for the EXTEND operator
### What changes were proposed in this pull request?
This PR adds SQL pipe syntax support for the EXTEND operator.
This operator preserves the existing input table and adds one or more new computed columns whose values are equal to evaluating the specified expressions. This is equivalent to `SELECT *, <newExpressions>` in the SQL compiler. It is provided as a convenience feature and some functionality overlap exists with lateral column aliases.
For example:
```
CREATE TABLE t(x INT, y STRING) USING CSV;
INSERT INTO t VALUES (0, 'abc'), (1, 'def');
TABLE t
|> EXTEND x + LENGTH(y) AS z;
+----+-----+-----+
| x | y | z |
+----+-----+-----+
| 0 | abc | 3 |
| 1 | def | 4 |
+----+-----+-----+
```
Like the `|> SELECT` operator, aggregate functions are not allowed in these expressions. During the course of developing reasonable error messages for this, I found that the SQL pipe syntax research paper also specified that the `|> AGGREGATE` operator should require that each non-grouping expression contains at least one aggregate function; I added a check and reasonable error message for this case as well.
### Why are the changes needed?
The SQL pipe operator syntax will let users compose queries in a more flexible fashion.
### Does this PR introduce _any_ user-facing change?
Yes, see above.
### How was this patch tested?
This PR adds a few unit test cases, but mostly relies on golden file test coverage. I did this to make sure the answers are correct as this feature is implemented and also so we can look at the analyzer output plans to ensure they look right as well.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #48854 from dtenedor/pipe-syntax-projections.
Authored-by: Daniel Tenedorio <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent 0fbd34c commit ea222a3
File tree
15 files changed
+618
-123
lines changed- common/utils/src/main/resources/error
- docs
- sql
- api/src/main/antlr4/org/apache/spark/sql/catalyst/parser
- catalyst/src/main/scala/org/apache/spark/sql
- catalyst
- expressions
- parser
- errors
- core/src/test
- resources/sql-tests
- analyzer-results
- inputs
- results
- nonansi
- scala/org/apache/spark/sql/execution
- hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver
15 files changed
+618
-123
lines changedLines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3995 | 3995 | | |
3996 | 3996 | | |
3997 | 3997 | | |
3998 | | - | |
| 3998 | + | |
3999 | 3999 | | |
4000 | | - | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
4001 | 4007 | | |
4002 | 4008 | | |
4003 | 4009 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1503 | 1503 | | |
1504 | 1504 | | |
1505 | 1505 | | |
| 1506 | + | |
1506 | 1507 | | |
1507 | 1508 | | |
1508 | 1509 | | |
| |||
1617 | 1618 | | |
1618 | 1619 | | |
1619 | 1620 | | |
| 1621 | + | |
1620 | 1622 | | |
1621 | 1623 | | |
1622 | 1624 | | |
| |||
1963 | 1965 | | |
1964 | 1966 | | |
1965 | 1967 | | |
| 1968 | + | |
1966 | 1969 | | |
1967 | 1970 | | |
1968 | 1971 | | |
| |||
Lines changed: 31 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | | - | |
| 32 | + | |
29 | 33 | | |
30 | | - | |
31 | | - | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | | - | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
47 | 58 | | |
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
| 65 | + | |
53 | 66 | | |
54 | 67 | | |
55 | 68 | | |
| 69 | + | |
56 | 70 | | |
57 | 71 | | |
58 | 72 | | |
| |||
Lines changed: 32 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1236 | 1236 | | |
1237 | 1237 | | |
1238 | 1238 | | |
1239 | | - | |
| 1239 | + | |
1240 | 1240 | | |
1241 | 1241 | | |
1242 | 1242 | | |
| |||
1293 | 1293 | | |
1294 | 1294 | | |
1295 | 1295 | | |
1296 | | - | |
| 1296 | + | |
1297 | 1297 | | |
1298 | 1298 | | |
1299 | 1299 | | |
1300 | | - | |
| 1300 | + | |
| 1301 | + | |
1301 | 1302 | | |
1302 | 1303 | | |
1303 | 1304 | | |
| |||
5933 | 5934 | | |
5934 | 5935 | | |
5935 | 5936 | | |
| 5937 | + | |
| 5938 | + | |
| 5939 | + | |
| 5940 | + | |
| 5941 | + | |
| 5942 | + | |
| 5943 | + | |
| 5944 | + | |
| 5945 | + | |
| 5946 | + | |
| 5947 | + | |
| 5948 | + | |
| 5949 | + | |
| 5950 | + | |
| 5951 | + | |
| 5952 | + | |
| 5953 | + | |
| 5954 | + | |
5936 | 5955 | | |
5937 | 5956 | | |
5938 | 5957 | | |
| |||
5959 | 5978 | | |
5960 | 5979 | | |
5961 | 5980 | | |
5962 | | - | |
| 5981 | + | |
5963 | 5982 | | |
5964 | 5983 | | |
5965 | 5984 | | |
| |||
5970 | 5989 | | |
5971 | 5990 | | |
5972 | 5991 | | |
| 5992 | + | |
| 5993 | + | |
5973 | 5994 | | |
5974 | 5995 | | |
5975 | 5996 | | |
5976 | | - | |
5977 | | - | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
| 6000 | + | |
| 6001 | + | |
| 6002 | + | |
| 6003 | + | |
5978 | 6004 | | |
5979 | 6005 | | |
5980 | 6006 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4135 | 4135 | | |
4136 | 4136 | | |
4137 | 4137 | | |
4138 | | - | |
| 4138 | + | |
4139 | 4139 | | |
4140 | | - | |
| 4140 | + | |
4141 | 4141 | | |
4142 | 4142 | | |
4143 | 4143 | | |
4144 | 4144 | | |
4145 | 4145 | | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
4146 | 4155 | | |
4147 | 4156 | | |
4148 | 4157 | | |
| |||
0 commit comments