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/02 07:05:23 UTC
[GitHub] [calcite] JiajunBernoulli opened a new pull request, #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
JiajunBernoulli opened a new pull request, #2847:
URL: https://github.com/apache/calcite/pull/2847
# insert values case
Here is the sql
```
insert into t3 values ('a', 1.0, 1), ('b', 2, 2), ('c', 3.0, CAST(3 AS SMALLINT)), ('d', 4.0, 4), ('e', 5.0, 5)
```
the validated sql is :
```
INSERT INTO `CATALOG`.`SALES`.`T3`
VALUES ROW('a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)),
ROW('b', 2, CAST(2 AS SMALLINT)),-- Encountered an integer and ended early
ROW('c', 3.0, CAST(3 AS SMALLINT)),Encountered an samllint and ended early
ROW('d', 4.0, 4), -- missing cast
ROW('e', 5.0, 5) -- missing cast
```
the right validated sql is:
```
INSERT INTO `CATALOG`.`SALES`.`T3`
VALUES ROW('a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)),
ROW('b', 2, CAST(2 AS SMALLINT)),
ROW('c', CAST(3.0 AS INTEGER), CAST(3 AS SMALLINT)),
ROW('d', CAST(4.0 AS INTEGER), CAST(4 AS SMALLINT)),
ROW('e', CAST(5.0 AS INTEGER), CAST(5 AS SMALLINT))
```
--
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] JiajunBernoulli commented on pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on PR #2847:
URL: https://github.com/apache/calcite/pull/2847#issuecomment-1181315028
@danny0405 , Would you please review the pull request that is from [CALCITE-4897](https://github.com/apache/calcite/pull/2615)?
Thanks you very much~
--
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] JiajunBernoulli commented on a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r918551024
##########
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml:
##########
@@ -2936,7 +2936,7 @@ values (10, 'Fred')]]>
<![CDATA[
LogicalTableModify(table=[[CATALOG, SALES, EMPNULLABLES]], operation=[INSERT], flattened=[true])
LogicalFilter(condition=[>($5, 1000)])
- LogicalProject(EMPNO=[$0], ENAME=[CAST($1):VARCHAR(20)], JOB=[null:VARCHAR(10)], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[null:INTEGER], COMM=[null:INTEGER], DEPTNO=[20], SLACKER=[null:BOOLEAN])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[null:VARCHAR(10)], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[null:INTEGER], COMM=[null:INTEGER], DEPTNO=[20], SLACKER=[null:BOOLEAN])
Review Comment:
ENAME is `varchar20Type`, so it is also expected.
--
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 a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
libenchao commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1039714710
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
Could you help me to understand the meaning of return value for `rowTypeCoercion`? Per my understanding, `true` means coercion has occurred, right?
--
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] JiajunBernoulli commented on a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r918549135
##########
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml:
##########
@@ -2897,7 +2897,7 @@ LogicalTableModify(table=[[SALES, EMPDEFAULTS]], operation=[INSERT], flattened=[
<Resource name="plan">
<![CDATA[
LogicalTableModify(table=[[SALES, EMPDEFAULTS]], operation=[INSERT], flattened=[true])
- LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[CAST($2):VARCHAR(10)], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[555], COMM=[null:INTEGER], DEPTNO=[20], SLACKER=[null:BOOLEAN])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[555], COMM=[null:INTEGER], DEPTNO=[20], SLACKER=[null:BOOLEAN])
Review Comment:
JOB is `varchar10TypeNull`, so it is expected.
--
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 closed pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
libenchao closed pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
URL: https://github.com/apache/calcite/pull/2847
--
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 a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
libenchao commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1042836225
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
> And the same logic should also be aligned in other similar methods
Sorry about my this comment, which is something misleading. In `rowTypeCoercion` method, only `VALUES` branch is wrong now, we'd better to only change this, and keep others unchanged, which will make this PR more clean.
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -94,27 +94,24 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
int columnIndex,
RelDataType targetType) {
final SqlKind kind = query.getKind();
+ boolean coerced = false;
switch (kind) {
case SELECT:
SqlSelect selectNode = (SqlSelect) query;
SqlValidatorScope scope1 = validator.getSelectScope(selectNode);
- if (!coerceColumnType(scope1, getSelectList(selectNode), columnIndex, targetType)) {
- return false;
- }
- updateInferredColumnType(scope1, query, columnIndex, targetType);
Review Comment:
We are updating the `scope1` instead of `scope`, however, after your change, we'll update `scope`.
--
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] JiajunBernoulli commented on a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1041636188
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
Good advice, I refactor the rowTypeCoercion function.
Thanks for your review very much!
--
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 a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
libenchao commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1040282037
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
Then IMO, the return value is totally wrong now, I should be
```java
boolean coerceValues = false;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
coerceValues = true;
}
}
if (coerceValues) {
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
}
return coerceValues;
```
And the same logic should also be aligned in other similar methods, WDYT?
--
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] JiajunBernoulli commented on a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1040264729
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
Yes, true means coercion has occurred, and so do `coerceOperandType`.
--
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] JiajunBernoulli commented on pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on PR #2847:
URL: https://github.com/apache/calcite/pull/2847#issuecomment-1343698418
Never mind, thank you for your review again.
--
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] JiajunBernoulli commented on a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r918550342
##########
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml:
##########
@@ -2885,7 +2885,7 @@ LogicalTableModify(table=[[CATALOG, SALES, EMPDEFAULTS]], operation=[INSERT], fl
<![CDATA[
LogicalTableModify(table=[[SALES, EMPDEFAULTS]], operation=[INSERT], flattened=[true])
LogicalFilter(condition=[=($7, 20)])
- LogicalProject(EMPNO=[$2], ENAME=[$0], JOB=[null:VARCHAR(10)], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[CAST($4):INTEGER], COMM=[null:INTEGER], DEPTNO=[CAST($1):INTEGER], SLACKER=[null:BOOLEAN], EXTRA=[null:BOOLEAN], UPDATED=[CAST($3):TIMESTAMP(0)])
+ LogicalProject(EMPNO=[$2], ENAME=[$0], JOB=[null:VARCHAR(10)], MGR=[null:INTEGER], HIREDATE=[null:TIMESTAMP(0)], SAL=[$4], COMM=[null:INTEGER], DEPTNO=[$1], SLACKER=[null:BOOLEAN], EXTRA=[null:BOOLEAN], UPDATED=[$3])
Review Comment:
SAL is `intTypeNull`, we don't need to cast.
--
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] JiajunBernoulli commented on pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
JiajunBernoulli commented on PR #2847:
URL: https://github.com/apache/calcite/pull/2847#issuecomment-1188749238
@beyond1920 , Would you please review the PR? You left a comment on https://github.com/apache/calcite/pull/2615. (The PR is from that PR)
Thank you very much~
--
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 a diff in pull request #2847: [CALCITE-5141] Incomplete implicit type conversion for insert values
Posted by GitBox <gi...@apache.org>.
libenchao commented on code in PR #2847:
URL: https://github.com/apache/calcite/pull/2847#discussion_r1040282037
##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -104,14 +104,15 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coerceValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
- return false;
+ coerceValues = false;
}
}
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ return coerceValues;
Review Comment:
Then IMO, the return value is totally wrong now, it should be
```java
boolean coerceValues = false;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
coerceValues = true;
}
}
if (coerceValues) {
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
}
return coerceValues;
```
And the same logic should also be aligned in other similar methods, WDYT?
--
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