-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7311] Support the syntax ROW(*) to create a nested ROW type with all columns #4665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| } | ||
|
|
||
| private List<SqlNode> expandRowStar(SqlIdentifier identifier, SelectScope scope) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we merge #4662 this should probably be enhanced to support EXCLUDE list in ROW(*) as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can consider supporting this in the next PR, because there is currently a limitation: the EXCLUDE syntax is only enabled in Babel. Should we also keep ROW(* EXCLUDE(...)) supported in Babel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both probably need to be in the same parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it in a subsequent PR is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both probably need to be in the same parser
I want to confirm, are you suggesting that the ROW(*) capability should also be fully supported in Babel? I’ve read through all the comments, and it seems this is the only remaining issue to address, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is fine to support ROW(*) in the main parser and ROW(* EXCLUDE) only in Babel
| new CallCopyingArgHandler(call, false); | ||
| call.getOperator().acceptCall(this, call, true, argHandler); | ||
| final SqlNode result = argHandler.result(); | ||
| final SqlNode result = expandRow(argHandler.result()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find is a bit weird to have expandRow happen as a side-effect of calculatePermuteOffset; maybe this is a sign that the function name should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rename expandRow to expandStarInRow.
| return node; | ||
| } | ||
| final SqlValidatorScope scope = getScope(); | ||
| if (!(scope instanceof SelectScope)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the scope is not Select? Will eventually an error be produced?
Or is this the right place to produce the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added error here.
| } | ||
|
|
||
| private void popRowValueStar() { | ||
| if (rowValueStarCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be false?
If not, maybe this can be an assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| LOOKAHEAD(3) | ||
| <ROW> { | ||
| s = span(); | ||
| pushRowValueStar(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point about nested ROW constructors.
I wonder what spark does.
It seems that ROW(*, ROW(*)) is legit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pgsql can support this syntax, following:
SELECT ROW(DEPT.*, ROW(DEPT.*)) FROM DEPT;
row
-----------------------------------------------------------
(10,ACCOUNTING,"NEW YORK","(10,ACCOUNTING,""NEW YORK"")")
(20,RESEARCH,DALLAS,"(20,RESEARCH,DALLAS)")
(30,SALES,CHICAGO,"(30,SALES,CHICAGO)")
(40,OPERATIONS,BOSTON,"(40,OPERATIONS,BOSTON)")
(4 rows)
It doesn't support ROW(*, ROW(*)). But I think we can support this form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I configured a Spark environment and tested the following SQL statements, all of which were executable.
spark-sql (mydb)> SELECT STRUCT(*) AS row_data FROM dept;
{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK"}
{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON"}
{"deptno":20,"dname":"RESEARCH","loc":"DALLAS"}
{"deptno":30,"dname":"SALES","loc":"CHICAGO"}
Time taken: 0.207 seconds, Fetched 4 row(s)
spark-sql (mydb)> SELECT STRUCT(*, STRUCT(*)) AS row_data FROM dept;
{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK","col2":{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK"}}
{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON","col2":{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON"}}
{"deptno":20,"dname":"RESEARCH","loc":"DALLAS","col2":{"deptno":20,"dname":"RESEARCH","loc":"DALLAS"}}
{"deptno":30,"dname":"SALES","loc":"CHICAGO","col2":{"deptno":30,"dname":"SALES","loc":"CHICAGO"}}
Time taken: 0.103 seconds, Fetched 4 row(s)
spark-sql (mydb)> SELECT STRUCT(*, STRUCT(dept.*)) AS row_data FROM dept;
{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK","col2":{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK"}}
{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON","col2":{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON"}}
{"deptno":20,"dname":"RESEARCH","loc":"DALLAS","col2":{"deptno":20,"dname":"RESEARCH","loc":"DALLAS"}}
{"deptno":30,"dname":"SALES","loc":"CHICAGO","col2":{"deptno":30,"dname":"SALES","loc":"CHICAGO"}}
Time taken: 0.075 seconds, Fetched 4 row(s)
| e = ContextVariable() | ||
| | | ||
| e = CompoundIdentifier() | ||
| | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The natural question that follows is about ROW(T.*). But that can be part of a follow-up PR, including perhaps ROW(T.* EXCLUDE(list))
| | | ||
| e = CompoundIdentifier() | ||
| | | ||
| LOOKAHEAD({ allowRowValueStar() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know that LOOKAHEAD allows a function call
|
Now that #4662 is merged, I plan to restart this work within the next few days. |
0009193 to
90c3ad0
Compare
90c3ad0 to
b6ba7a8
Compare
|



See CALCITE-7311