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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]