You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "xuzifu666 (via GitHub)" <gi...@apache.org> on 2026/05/13 12:15:24 UTC
[PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
xuzifu666 opened a new pull request, #4939:
URL: https://github.com/apache/calcite/pull/4939
jira: https://issues.apache.org/jira/browse/CALCITE-7523
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4441459698
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939) **Quality Gate passed**
Issues
 [5 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [92.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4447044645
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238669538
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -275,6 +275,61 @@ names, is(
.fails("SELECT \\* EXCLUDE/EXCEPT list cannot exclude all columns");
}
+ /** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-7532">
+ * [CALCITE-7532] Support the syntax SELECT * REPLACE(expr as column)</a>.
+ * */
+ @Test void testStarReplaceValidation() {
+ final SqlValidatorFixture fixture = Fixtures.forValidator()
+ .withParserConfig(p -> p.withParserFactory(SqlBabelParserImpl.FACTORY));
+
+ fixture.withSql("select * replace(empno + 1 as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // Verify that EMPNO type is still INTEGER (or similar)
+ assertThat(type.getFieldList().get(0).getType().getSqlTypeName().getName(),
+ is("INTEGER"));
+ });
+
+ fixture.withSql("select * replace(empno + 1 as empno, sal * 2 as sal) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ });
+
+ // Unknown column in REPLACE list
+ fixture.withSql("select * replace(empno + 1 as ^foo^) from emp")
+ .fails("SELECT \\* REPLACE list contains unknown column\\(s\\): FOO");
+
+ // Table-qualified star with REPLACE
+ fixture.withSql("select e.* replace(e.empno + 1 as e.empno)"
+ + " from emp e join dept d on e.deptno = d.deptno")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ });
+
+ // REPLACE with unknown qualified column
+ fixture.withSql("select e.* replace(e.empno + 1 as ^d.deptno^)"
Review Comment:
Related test cases had been added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3245453191
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -307,6 +306,36 @@ names, is(
"HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
});
+ // REPLACE with a completely different type
+ fixture.withSql("select * replace('fixed' as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // EMPNO was INTEGER, now replaced by a CHAR literal
+ assertThat(type.getFieldList().get(0).getType().getSqlTypeName().getName(),
+ is("CHAR"));
+ });
+
+ // Same column replaced twice: the last one wins
+ fixture.withSql("select * replace(empno + 1 as empno, 'fixed' as empno) from emp")
Review Comment:
I have already approved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3236210964
##########
babel/src/main/codegen/config.fmpp:
##########
@@ -618,6 +618,7 @@ data: {
includeParsingStringLiteralAsArrayLiteral: true
includeIntervalWithoutQualifier: true
includeStarExclude: true
+ includeStarReplace: true
Review Comment:
I wonder whether this should reuse the same flag as StarExclude.
Too many flags are harder to manage.
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -275,6 +275,61 @@ names, is(
.fails("SELECT \\* EXCLUDE/EXCEPT list cannot exclude all columns");
}
+ /** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-7532">
+ * [CALCITE-7532] Support the syntax SELECT * REPLACE(expr as column)</a>.
+ * */
+ @Test void testStarReplaceValidation() {
+ final SqlValidatorFixture fixture = Fixtures.forValidator()
+ .withParserConfig(p -> p.withParserFactory(SqlBabelParserImpl.FACTORY));
+
+ fixture.withSql("select * replace(empno + 1 as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // Verify that EMPNO type is still INTEGER (or similar)
Review Comment:
how about one test where the new column has a completely different type?
I assume that's possible
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -661,8 +672,35 @@ private boolean expandStar(List<SqlNode> selectItems, Set<String> aliases,
final List<SqlIdentifier> excludeIdentifiers =
excludeList == null ? Collections.emptyList() : extractExcludeIdentifiers(excludeList);
final boolean[] excludeMatched = new boolean[excludeIdentifiers.size()];
+ final Map<String, SqlNode> replaceMap =
Review Comment:
it looks like you can just call extractReplaceMap, it checks for null itself
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -275,6 +275,61 @@ names, is(
.fails("SELECT \\* EXCLUDE/EXCEPT list cannot exclude all columns");
}
+ /** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-7532">
+ * [CALCITE-7532] Support the syntax SELECT * REPLACE(expr as column)</a>.
+ * */
+ @Test void testStarReplaceValidation() {
+ final SqlValidatorFixture fixture = Fixtures.forValidator()
+ .withParserConfig(p -> p.withParserFactory(SqlBabelParserImpl.FACTORY));
+
+ fixture.withSql("select * replace(empno + 1 as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // Verify that EMPNO type is still INTEGER (or similar)
+ assertThat(type.getFieldList().get(0).getType().getSqlTypeName().getName(),
+ is("INTEGER"));
+ });
+
+ fixture.withSql("select * replace(empno + 1 as empno, sal * 2 as sal) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ });
+
+ // Unknown column in REPLACE list
+ fixture.withSql("select * replace(empno + 1 as ^foo^) from emp")
+ .fails("SELECT \\* REPLACE list contains unknown column\\(s\\): FOO");
+
+ // Table-qualified star with REPLACE
+ fixture.withSql("select e.* replace(e.empno + 1 as e.empno)"
+ + " from emp e join dept d on e.deptno = d.deptno")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ });
+
+ // REPLACE with unknown qualified column
+ fixture.withSql("select e.* replace(e.empno + 1 as ^d.deptno^)"
Review Comment:
how about a test where the same column is replaced twice?
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -903,6 +986,82 @@ private void throwIfExcludeEliminatesAllColumns(List<SqlIdentifier> excludeIdent
}
}
+ private static Map<String, SqlNode> extractReplaceMap(@Nullable SqlNodeList replaceList) {
+ if (replaceList == null) {
+ return ImmutableMap.of();
+ }
+ final ImmutableMap.Builder<String, SqlNode> builder = ImmutableMap.builder();
+ for (SqlNode node : replaceList) {
+ if (node instanceof SqlCall) {
Review Comment:
what if it's not a SqlCall?
Some missing assertion?
##########
site/_docs/reference.md:
##########
@@ -244,9 +244,14 @@ starWithExclude:
*
| * EXCLUDE '(' column [, column ]* ')'
+starWithReplace:
+ *
+ | * REPLACE '(' expression AS column [, expression AS column ]* ')'
+
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.
Review Comment:
I don't understand exactly the last sentence. Does it even belong in the reference? Seems to be more useful for developers.
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -781,6 +841,28 @@ private boolean expandStar(List<SqlNode> selectItems, Set<String> aliases,
if (shouldExcludeField(excludeList, columnId, resolvedNameMatcher)) {
continue;
}
+ final SqlNode replacement =
+ findReplacement(columnName, replaceMap, resolvedNameMatcher);
+ if (replacement != null) {
Review Comment:
if this check fails is there an error thrown later?
Then please document this after the if
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3245340198
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -307,6 +306,36 @@ names, is(
"HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
});
+ // REPLACE with a completely different type
+ fixture.withSql("select * replace('fixed' as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // EMPNO was INTEGER, now replaced by a CHAR literal
+ assertThat(type.getFieldList().get(0).getType().getSqlTypeName().getName(),
+ is("CHAR"));
+ });
+
+ // Same column replaced twice: the last one wins
+ fixture.withSql("select * replace(empno + 1 as empno, 'fixed' as empno) from emp")
Review 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238666726
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -661,8 +672,35 @@ private boolean expandStar(List<SqlNode> selectItems, Set<String> aliases,
final List<SqlIdentifier> excludeIdentifiers =
excludeList == null ? Collections.emptyList() : extractExcludeIdentifiers(excludeList);
final boolean[] excludeMatched = new boolean[excludeIdentifiers.size()];
+ final Map<String, SqlNode> replaceMap =
Review Comment:
Yes, I removed the invalid reference here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3243478880
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -307,6 +306,36 @@ names, is(
"HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
});
+ // REPLACE with a completely different type
+ fixture.withSql("select * replace('fixed' as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // EMPNO was INTEGER, now replaced by a CHAR literal
+ assertThat(type.getFieldList().get(0).getType().getSqlTypeName().getName(),
+ is("CHAR"));
+ });
+
+ // Same column replaced twice: the last one wins
+ fixture.withSql("select * replace(empno + 1 as empno, 'fixed' as empno) from emp")
Review 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238668362
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -903,6 +986,82 @@ private void throwIfExcludeEliminatesAllColumns(List<SqlIdentifier> excludeIdent
}
}
+ private static Map<String, SqlNode> extractReplaceMap(@Nullable SqlNodeList replaceList) {
+ if (replaceList == null) {
+ return ImmutableMap.of();
+ }
+ final ImmutableMap.Builder<String, SqlNode> builder = ImmutableMap.builder();
+ for (SqlNode node : replaceList) {
+ if (node instanceof SqlCall) {
Review Comment:
Here I have added the relevant assertions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4447405857
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238664646
##########
site/_docs/reference.md:
##########
@@ -244,9 +244,14 @@ starWithExclude:
*
| * EXCLUDE '(' column [, column ]* ')'
+starWithReplace:
+ *
+ | * REPLACE '(' expression AS column [, expression AS column ]* ')'
+
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.
Review Comment:
I did some changes here to make it more clear.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4470317716
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238663066
##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -275,6 +275,61 @@ names, is(
.fails("SELECT \\* EXCLUDE/EXCEPT list cannot exclude all columns");
}
+ /** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-7532">
+ * [CALCITE-7532] Support the syntax SELECT * REPLACE(expr as column)</a>.
+ * */
+ @Test void testStarReplaceValidation() {
+ final SqlValidatorFixture fixture = Fixtures.forValidator()
+ .withParserConfig(p -> p.withParserFactory(SqlBabelParserImpl.FACTORY));
+
+ fixture.withSql("select * replace(empno + 1 as empno) from emp")
+ .type(type -> {
+ final List<String> names = type.getFieldList().stream()
+ .map(RelDataTypeField::getName)
+ .collect(Collectors.toList());
+ assertThat(
+ names, is(
+ ImmutableList.of("EMPNO", "ENAME", "JOB", "MGR",
+ "HIREDATE", "SAL", "COMM", "DEPTNO", "SLACKER")));
+ // Verify that EMPNO type is still INTEGER (or similar)
Review Comment:
Yes, I had added related test cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238661554
##########
babel/src/main/codegen/config.fmpp:
##########
@@ -618,6 +618,7 @@ data: {
includeParsingStringLiteralAsArrayLiteral: true
includeIntervalWithoutQualifier: true
includeStarExclude: true
+ includeStarReplace: true
Review Comment:
That makes sense. I've combined those two parameters and will only use one to support it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4456551216
If there no other comments, I will squash and merge it in next 48h.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 merged PR #4939:
URL: https://github.com/apache/calcite/pull/4939
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4939:
URL: https://github.com/apache/calcite/pull/4939#discussion_r3238675231
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -781,6 +841,28 @@ private boolean expandStar(List<SqlNode> selectItems, Set<String> aliases,
if (shouldExcludeField(excludeList, columnId, resolvedNameMatcher)) {
continue;
}
+ final SqlNode replacement =
+ findReplacement(columnName, replaceMap, resolvedNameMatcher);
+ if (replacement != null) {
Review Comment:
Had document this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7523] Support the syntax SELECT * REPLACE(expr as column) [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4939:
URL: https://github.com/apache/calcite/pull/4939#issuecomment-4456304632
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4939&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4939&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4939)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org