You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/07/17 17:04:02 UTC
[GitHub] [calcite] hailin0 opened a new pull request, #2855: [CALCITE-5214] Implicit type conversion fails in union sql
hailin0 opened a new pull request, #2855:
URL: https://github.com/apache/calcite/pull/2855
https://issues.apache.org/jira/browse/CALCITE-5214
The following test:
```java
//org.apache.calcite.test.SqlToRelConverterTest
@Test void testUnionNullableImplicitTypeCoercion() {
final String sql = "select id from (values(1), (null)) t (id) union select 'varchar-id' as id";
sql(sql).ok();
}
```
Fails with the following exception:
```java
Exception in thread "main" java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes:
validated type:
RecordType(VARCHAR NOT NULL ID) NOT NULL
converted type:
RecordType(VARCHAR EXPR$0) NOT NULL
rel:
LogicalUnion(all=[false])
LogicalProject(EXPR$0=[CAST($0):VARCHAR])
LogicalValues(tuples=[[{ 1 }, { null }]])
LogicalValues(tuples=[[{ 'varchar-id' }]]) at org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:486)
at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:601)
at org.apache.calcite.prepare.PlannerImpl.rel(PlannerImpl.java:259)
```
--
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
[GitHub] [calcite] chunweilei commented on a diff in pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by GitBox <gi...@apache.org>.
chunweilei commented on code in PR #2855:
URL: https://github.com/apache/calcite/pull/2855#discussion_r922932458
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java:
##########
@@ -436,11 +436,13 @@ private RelDataType getTightestCommonTypeOrThrow(
// 2. VARCHAR has 65536 as default precision.
// 3. Following MS-SQL: BINARY or BOOLEAN can be casted to VARCHAR.
if (SqlTypeUtil.isAtomic(type1) && SqlTypeUtil.isCharacter(type2)) {
- resultType = factory.createSqlType(SqlTypeName.VARCHAR);
+ resultType = factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.VARCHAR),
+ type1.isNullable() || type2.isNullable());
}
if (SqlTypeUtil.isCharacter(type1) && SqlTypeUtil.isAtomic(type2)) {
- resultType = factory.createSqlType(SqlTypeName.VARCHAR);
+ resultType = factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.VARCHAR),
+ type1.isNullable() || type2.isNullable());
}
Review Comment:
Do other kinds of conversions have the same 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
[GitHub] [calcite] hailin0 closed pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 closed pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
URL: https://github.com/apache/calcite/pull/2855
--
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
[GitHub] [calcite] hailin0 commented on a diff in pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2855:
URL: https://github.com/apache/calcite/pull/2855#discussion_r922942312
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java:
##########
@@ -436,11 +436,13 @@ private RelDataType getTightestCommonTypeOrThrow(
// 2. VARCHAR has 65536 as default precision.
// 3. Following MS-SQL: BINARY or BOOLEAN can be casted to VARCHAR.
if (SqlTypeUtil.isAtomic(type1) && SqlTypeUtil.isCharacter(type2)) {
- resultType = factory.createSqlType(SqlTypeName.VARCHAR);
+ resultType = factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.VARCHAR),
+ type1.isNullable() || type2.isNullable());
}
if (SqlTypeUtil.isCharacter(type1) && SqlTypeUtil.isAtomic(type2)) {
- resultType = factory.createSqlType(SqlTypeName.VARCHAR);
+ resultType = factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.VARCHAR),
+ type1.isNullable() || type2.isNullable());
}
Review Comment:
https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java#L543-L548
Other type conversions already handle nullable settings in the getTightestCommonType method
--
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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-2447746607
This may be solved by https://github.com/apache/calcite/pull/4024
--
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
[GitHub] [calcite] hailin0 commented on pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-1460218492
> @hailin0 The checkstyle has changed recently, could you resolve these failures first and let the CI pass?
please recheck
--
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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-2447838625
I have checked that https://github.com/apache/calcite/pull/4024 does indeed solve this problem as well.
Since that solution is more general, let's wait a bit to see whether this PR is still necessary.
However, the changes proposed here make sense, and maybe they are useful for other cases than set operations.
--
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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-2447593959
please recheck
--
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
[GitHub] [calcite] libenchao commented on pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by "libenchao (via GitHub)" <gi...@apache.org>.
libenchao commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-1451305631
@hailin0 The checkstyle has changed recently, could you resolve these failures first and let the CI pass?
--
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
[GitHub] [calcite] hailin0 commented on pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-1450056551
@NobiGo
@chunweilei
Please help to 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
[GitHub] [calcite] hailin0 commented on pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-1460288694
what should i do
```xml
FAILURE 0.0sec, org.apache.calcite.test.SqlToRelConverterTest > executionError
java.lang.IllegalArgumentException: Actual and reference files differ. If you are adding new tests, replace the reference file with the current actual file, after checking its content.
diff /home/runner/work/calcite/calcite/core/build/resources/test/org/apache/calcite/test/SqlToRelConverterTest_actual.xml /home/runner/work/calcite/calcite/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
7854,7855c7854
< <![CDATA[select id from (values(1), (null)) t (id)
< union select 'varchar-id' as id]]>
---
> <![CDATA[select id from (values(1), (null)) t (id) union select 'varchar-id' as id]]>
at org.apache.calcite.test.DiffRepository.checkActualAndReferenceFiles(DiffRepository.java:261)
at org.apache.calcite.test.SqlToRelConverterTest.checkActualAndReferenceFiles(SqlToRelConverterTest.java:90)
```
--
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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu closed pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
URL: https://github.com/apache/calcite/pull/2855
--
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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-2447848450
In fact, in the current main I could not reproduce this bug, it may have been solved by https://github.com/apache/calcite/pull/2803
Can you please make sure that the bug is still there? If not, please close this issue and 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-5214] Implicit type conversion fails in union sql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #2855:
URL: https://github.com/apache/calcite/pull/2855#discussion_r1823005329
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java:
##########
@@ -445,11 +445,15 @@ private RelDataType getTightestCommonTypeOrThrow(
// 2. VARCHAR has 65536 as default precision.
// 3. Following MS-SQL: BINARY or BOOLEAN can be casted to VARCHAR.
if (SqlTypeUtil.isAtomic(type1) && SqlTypeUtil.isCharacter(type2)) {
- resultType = factory.createSqlType(SqlTypeName.VARCHAR);
+ resultType =
+ factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.VARCHAR),
Review Comment:
these changes are not really related to union.
But this may be the right approach.
--
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
[GitHub] [calcite] hailin0 commented on pull request #2855: [CALCITE-5214] Implicit type conversion fails in union sql
Posted by GitBox <gi...@apache.org>.
hailin0 commented on PR #2855:
URL: https://github.com/apache/calcite/pull/2855#issuecomment-1186681960
@NobiGo
@chunweilei
Please help to 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