[CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column)#4939
[CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column)#4939xuzifu666 wants to merge 12 commits into
Conversation
| Note: | ||
|
|
||
| * `SELECT * EXCLUDE (...)` is recognized only when the Babel parser is enabled. It sets the generated parser configuration flag `includeStarExclude` to `true` (the standard parser leaves that flag `false`), which allows a `STAR` token followed by `EXCLUDE` (or the alias `EXCEPT`) and a parenthesized identifier list to be parsed into a `SqlStarExclude` node and ensures validators respect the exclusion list when expanding the projection. Reusing the same parser configuration elsewhere enables the same syntax for other components that need it. | ||
| * `SELECT * REPLACE (...)` is recognized only when the Babel parser is enabled. It sets the generated parser configuration flag `includeStarReplace` to `true` (the standard parser leaves that flag `false`), which allows a `STAR` token followed by `REPLACE` and a parenthesized list of `expression AS column` pairs to be parsed into a `SqlStarReplace` node and ensures validators substitute the specified expressions for the matching columns when expanding the projection. The column alias must either be a simple identifier or, for a table-qualified star such as `t.*`, a qualified identifier whose prefix matches the star's table alias. Reusing the same parser configuration elsewhere enables the same syntax for other components that need it. |
There was a problem hiding this comment.
I don't understand exactly the last sentence. Does it even belong in the reference? Seems to be more useful for developers.
There was a problem hiding this comment.
I did some changes here to make it more clear.
| } | ||
| final SqlNode replacement = | ||
| findReplacement(columnName, replaceMap, resolvedNameMatcher); | ||
| if (replacement != null) { |
There was a problem hiding this comment.
if this check fails is there an error thrown later?
Then please document this after the if
| }); | ||
|
|
||
| // Same column replaced twice: the last one wins | ||
| fixture.withSql("select * replace(empno + 1 as empno, 'fixed' as empno) from emp") |
There was a problem hiding this comment.
is this the semantics in other systems?
I find this a bit dangerous, I expected it to be an error
But we should emulate what others do
There was a problem hiding this comment.
That makes sense! I agree with this point. My tests on relevant databases (including ClickHouse https://fiddle.clickhouse.com/1f06c0d0-9704-4611-bd03-e5c31cd4e4fe) show that not support multiple replace statements. I've modified the output here to show an error. Thanks for the suggestion.
There was a problem hiding this comment.
I have already approved
|
|
If there no other comments, I will squash and merge it in next 48h. |



jira: https://issues.apache.org/jira/browse/CALCITE-7523