You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "xiedeyantu (via GitHub)" <gi...@apache.org> on 2025/10/16 16:01:35 UTC
[PR] [CALCITE-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
xiedeyantu opened a new pull request, #4584:
URL: https://github.com/apache/calcite/pull/4584
See: [CALCITE-7233](https://issues.apache.org/jira/browse/CALCITE-7233)
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "bestbeforetoday (via GitHub)" <gi...@apache.org>.
bestbeforetoday commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3415400860
These SQL files, which present alternate forms of the TPC-DS queries, are not actually being used by the tests:
- `plus/src/test/resources/sql/tpcds/27a.sql`
- `plus/src/test/resources/sql/tpcds/36a.sql`
- `plus/src/test/resources/sql/tpcds/70a.sql`
- `plus/src/test/resources/sql/tpcds/86a.sql`
They could be removed.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3416300387
Thanks for your quickly reply @mihaibudiu and @asolimando , I will merge this PR now.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411608551
We should probably remove other tpcds stubs that appear in the code.
That should probably be a different issue.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3416278073
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584)
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411618923
I haven't had the chance to construct a minimal test case yet, but based on the existing tests, the current modifications pass all 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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3413215088
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584)
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4584:
URL: https://github.com/apache/calcite/pull/4584#discussion_r2436608830
##########
plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql2rel;
+
+import org.apache.calcite.adapter.tpcds.TpcdsSchema;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Unit test demonstrating SQL to Rel conversion errors on TPC-DS queries 40, 67 and 80.
Review Comment:
This could be more general: compile TPCDS queries to Rel.
And it could also be a test case for the issue, but that will be less important as time goes on.
##########
plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql2rel;
+
+import org.apache.calcite.adapter.tpcds.TpcdsSchema;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Unit test demonstrating SQL to Rel conversion errors on TPC-DS queries 40, 67 and 80.
+ */
+public class TpcdsSqlToRelTest {
+
+ private static final RelDataTypeSystem TYPE_SYSTEM = new RelDataTypeSystemImpl() {
+ };
+ private static final CalciteCatalogReader TPCDS_CATALOG =
+ schemaToCatalog("tpcds", new TpcdsSchema(1.0), TYPE_SYSTEM);
+
+ static IntStream testCases() {
+ return IntStream.rangeClosed(1, 99);
+ }
+
+ private static CalciteCatalogReader schemaToCatalog(String schemaName, Schema schema,
+ RelDataTypeSystem typeSystem) {
+ CalciteSchema rootSchema = CalciteSchema.createRootSchema(false);
+ rootSchema.add(schemaName, schema);
+ List<String> defaultSchema = Collections.singletonList(schemaName);
+ return new CalciteCatalogReader(
+ rootSchema,
+ defaultSchema,
+ new JavaTypeFactoryImpl(typeSystem),
+ CalciteConnectionConfig.DEFAULT.set(
+ CalciteConnectionProperty.CASE_SENSITIVE, Boolean.FALSE.toString()));
+ }
+
+ @ParameterizedTest
+ @MethodSource("testCases")
+ public void testQuery(int query) throws IOException, SqlParseException {
+ String sql = getResourceAsString(inputSqlFile(query));
+ List<SqlNode> sqlNodes = parseSqlStatements(sql);
+ convertSqlToRel(sqlNodes);
+ }
+
+ private String inputSqlFile(int query) {
+ return String.format(Locale.getDefault(), "sql/tpcds/%02d.sql", query);
+ }
+
+ private String getResourceAsString(String name) throws IOException {
+ try (InputStream in = getClass().getClassLoader().getResourceAsStream(name);
+ Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
+ BufferedReader bufferedReader = new BufferedReader(reader)) {
+ return bufferedReader.lines().collect(Collectors.joining("\n"));
+ }
+ }
+
+ private List<SqlNode> parseSqlStatements(String sql) throws SqlParseException {
+ SqlParser.Config config = SqlParser.config()
+ .withUnquotedCasing(Casing.TO_UPPER)
+ .withConformance(SqlConformanceEnum.LENIENT)
+ .withParserFactory(SqlParserImpl.FACTORY);
+ SqlParser parser = SqlParser.create(sql, config);
+ return parser.parseStmtList();
+ }
+
+ private List<RelRoot> convertSqlToRel(List<SqlNode> sqlNodes) {
+ SqlToRelConverter converter = newSqlToRelConverter();
+ return sqlNodes.stream()
+ .map(sqlNode -> converter.convertQuery(sqlNode, true, true))
+ .collect(Collectors.toList());
+ }
+
+ private SqlToRelConverter newSqlToRelConverter() {
Review Comment:
I could probably replace "new" with "create" here and below
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411624707
Having more tests is always good.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411634730
> We should probably remove other tpcds stubs that appear in the code. That should probably be a different issue.
I agree. I also briefly checked the previous TPCDS tests and noticed they have been in a disabled state all along. I'm not quite sure why that is. However, the test case written by @bestbeforetoday looks pretty good. Should we consider standardizing its format and keeping it, or should we modify the existing ones? I don't have many strong opinions on 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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4584:
URL: https://github.com/apache/calcite/pull/4584#discussion_r2437939375
##########
core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java:
##########
@@ -298,11 +298,13 @@ private StandardConvertletTable() {
// Expand "CAST NOT NULL(x)" into "CAST(x AS INTEGER NOT NULL)"
registerOp(SqlInternalOperators.CAST_NOT_NULL,
- (cx, call) ->
- cx.getRexBuilder().makeCast(
- cx.getTypeFactory().createTypeWithNullability(
- cx.getValidator().getValidatedNodeType(call), false),
Review Comment:
Thank you for your detailed explanation!
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3416274472
You already have two approvals, why do you need another review?
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411664185
Thank you @mihaibudiu for the review. I’ve only replicated @bestbeforetoday’s tests for now. If we transition to Calcite’s native approach, I’d appreciate more suggestions from you. @bestbeforetoday, it’d be great if you could also take a look. Looking forward to your replies.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3411689379
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4584&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4584&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4584&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4584)
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3416188747
> These SQL files, which present alternate forms of the TPC-DS queries, are not actually being used by the tests:
>
> * `plus/src/test/resources/sql/tpcds/27a.sql`
> * `plus/src/test/resources/sql/tpcds/36a.sql`
> * `plus/src/test/resources/sql/tpcds/70a.sql`
> * `plus/src/test/resources/sql/tpcds/86a.sql`
>
> My bad for including them in the reproduce. They could be removed.
>
> Otherwise it looks good to me. Thank you for dealing with the issue so quickly.
Thank you for the review. I've deleted those files and squashed the commits while I was at it. I noticed that @mihaibudiu requested a review from @NobiGo . I'm not entirely sure who will be able to perform the final review and merge this PR.
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "asolimando (via GitHub)" <gi...@apache.org>.
asolimando commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3416285578
We are good to go @xiedeyantu, thanks a lot for jumping in and helping out!
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu merged PR #4584:
URL: https://github.com/apache/calcite/pull/4584
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "asolimando (via GitHub)" <gi...@apache.org>.
asolimando commented on code in PR #4584:
URL: https://github.com/apache/calcite/pull/4584#discussion_r2436930940
##########
plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql2rel;
+
+import org.apache.calcite.adapter.tpcds.TpcdsSchema;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Unit test demonstrating SQL to Rel conversion errors on TPC-DS queries 40, 67 and 80.
+ */
+public class TpcdsSqlToRelTest {
Review Comment:
nit: `public` can be dropped
##########
core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java:
##########
@@ -298,11 +298,13 @@ private StandardConvertletTable() {
// Expand "CAST NOT NULL(x)" into "CAST(x AS INTEGER NOT NULL)"
registerOp(SqlInternalOperators.CAST_NOT_NULL,
- (cx, call) ->
- cx.getRexBuilder().makeCast(
- cx.getTypeFactory().createTypeWithNullability(
- cx.getValidator().getValidatedNodeType(call), false),
Review Comment:
From a quick look, the `convertExpression` method can handle the column name as not fully qualified, and will successfully turn it into a fully qualified one then look it up, while `getValidatedNodeType` don't manage to do that, and it seems that at this stage, it's relying on the identifier to have been validated/visited earlier, which isn't the case.
Although I am not very familiar with this part of the codebase, I think the change is safe as in the file there is no use of `getValidatedNodeType`, while `convertExpression` on operands is used, probably the original code wasn't safe in all cases.
##########
plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql2rel;
+
+import org.apache.calcite.adapter.tpcds.TpcdsSchema;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Unit test demonstrating SQL to Rel conversion errors on TPC-DS queries 40, 67 and 80.
+ */
+public class TpcdsSqlToRelTest {
+
+ private static final RelDataTypeSystem TYPE_SYSTEM = new RelDataTypeSystemImpl() {
+ };
+ private static final CalciteCatalogReader TPCDS_CATALOG =
+ schemaToCatalog("tpcds", new TpcdsSchema(1.0), TYPE_SYSTEM);
+
+ static IntStream testCases() {
+ return IntStream.rangeClosed(1, 99);
+ }
+
+ private static CalciteCatalogReader schemaToCatalog(String schemaName, Schema schema,
+ RelDataTypeSystem typeSystem) {
+ CalciteSchema rootSchema = CalciteSchema.createRootSchema(false);
+ rootSchema.add(schemaName, schema);
+ List<String> defaultSchema = Collections.singletonList(schemaName);
+ return new CalciteCatalogReader(
+ rootSchema,
+ defaultSchema,
+ new JavaTypeFactoryImpl(typeSystem),
+ CalciteConnectionConfig.DEFAULT.set(
+ CalciteConnectionProperty.CASE_SENSITIVE, Boolean.FALSE.toString()));
+ }
+
+ @ParameterizedTest
+ @MethodSource("testCases")
+ public void testQuery(int query) throws IOException, SqlParseException {
Review Comment:
nit: `public` can be dropped
##########
plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql2rel;
+
+import org.apache.calcite.adapter.tpcds.TpcdsSchema;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Unit test demonstrating SQL to Rel conversion errors on TPC-DS queries 40, 67 and 80.
Review Comment:
Agreed, I think that having a tpcds-based test set for sql2rel is very valuable beyond the problem at hand
--
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-7233] SqlToRelConverter throws `UnsupportedOperationException` after the introduction of the internal `CAST_NON_NULL` operator [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4584:
URL: https://github.com/apache/calcite/pull/4584#issuecomment-3413175287
Thank you all for your suggestions. I've made adjustments based on the comments. Please take another look.
--
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