You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by da...@apache.org on 2021/02/22 06:57:34 UTC
[calcite] branch master updated: [CALCITE-4265] Improve error
message when CAST to unknown type (Louis Kuang)
This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 207bc8a [CALCITE-4265] Improve error message when CAST to unknown type (Louis Kuang)
207bc8a is described below
commit 207bc8a0d731fa40e84309dfea3f8189b383e117
Author: Louis Kuang <lo...@google.com>
AuthorDate: Wed Jan 13 21:31:38 2021 -0500
[CALCITE-4265] Improve error message when CAST to unknown type (Louis
Kuang)
If SqlNode is an Identifier node whose type can not be derived, throws
a validation error instead of an UnsupportedOperationException to improve
error message.
close apache/calcite#2326
---
.../java/org/apache/calcite/sql/validate/SqlValidatorImpl.java | 3 +++
.../test/java/org/apache/calcite/test/SqlValidatorTest.java | 10 +++++-----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 53c3f09..e83d213 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -1759,6 +1759,9 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
@Override public RelDataType getValidatedNodeType(SqlNode node) {
RelDataType type = getValidatedNodeTypeIfKnown(node);
if (type == null) {
+ if (node.getKind() == SqlKind.IDENTIFIER) {
+ throw newValidationError(node, RESOURCE.unknownIdentifier(node.toString()));
+ }
throw Util.needToImplement(node);
} else {
return type;
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 679464b..cfab141 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -1244,8 +1244,8 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
}
@Test void testCastRegisteredType() {
- expr("cast(123 as customBigInt)")
- .fails("class org.apache.calcite.sql.SqlIdentifier: CUSTOMBIGINT");
+ expr("cast(123 as ^customBigInt^)")
+ .fails("Unknown identifier 'CUSTOMBIGINT'");
expr("cast(123 as sales.customBigInt)")
.columnType("BIGINT NOT NULL");
expr("cast(123 as catalog.sales.customBigInt)")
@@ -1254,7 +1254,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
@Test void testCastFails() {
expr("cast('foo' as ^bar^)")
- .fails("class org.apache.calcite.sql.SqlIdentifier: BAR");
+ .fails("Unknown identifier 'BAR'");
wholeExpr("cast(multiset[1] as integer)")
.fails("(?s).*Cast function cannot convert value of type "
+ "INTEGER MULTISET to type INTEGER");
@@ -8007,9 +8007,9 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
+ "VARCHAR(5) NOT NULL ARRAY NOT NULL F1) NOT NULL "
+ "ARRAY NOT NULL MULTISET NOT NULL");
// test UDT collection type.
- sql("select cast(a as MyUDT array multiset) from COMPLEXTYPES.CTC_T1")
+ sql("select cast(a as ^MyUDT^ array multiset) from COMPLEXTYPES.CTC_T1")
.withExtendedCatalog()
- .fails("(?s).*class org\\.apache\\.calcite\\.sql\\.SqlIdentifier: MYUDT.*");
+ .fails("Unknown identifier 'MYUDT'");
}
@Test void testCastAsRowType() {