JiajunBernoulli commented on a change in pull request #2615:
URL: https://github.com/apache/calcite/pull/2615#discussion_r757753872
##########
File path:
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
##########
@@ -104,14 +104,17 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory,
SqlValidator validator)
updateInferredColumnType(scope1, query, columnIndex, targetType);
return true;
case VALUES:
+ boolean coercedValues = true;
for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex,
targetType)) {
- return false;
+ coercedValues = false;
}
}
- updateInferredColumnType(
- requireNonNull(scope, "scope"), query, columnIndex, targetType);
- return true;
+ if (coercedValues) {
+ updateInferredColumnType(
+ requireNonNull(scope, "scope"), query, columnIndex, targetType);
Review comment:
I thought so at first. But many test will be failed, for example:
```
sql("select 1 from (values(true)) union values (select '1' from (values
(true)) as tt)")
.type("RecordType(VARCHAR EXPR$0) NOT NULL");
```
```
org.opentest4j.AssertionFailedError: expected: <RecordType(VARCHAR EXPR$0)
NOT NULL>
but was: <RecordType(VARCHAR NOT NULL EXPR$0) NOT NULL>
```
I think it is only executed when coerced values is true, like the following
code
```
// Update the nested SET operator node type.
if (coerced) {
updateInferredColumnType(
requireNonNull(scope, "scope"), query, columnIndex, targetType);
}
```
##########
File path:
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
##########
@@ -121,8 +124,8 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory,
SqlValidator validator)
// Set operations are binary for now.
final SqlCall operand0 = ((SqlCall) query).operand(0);
final SqlCall operand1 = ((SqlCall) query).operand(1);
- final boolean coerced = rowTypeCoercion(scope, operand0, columnIndex,
targetType)
- && rowTypeCoercion(scope, operand1, columnIndex, targetType);
+ boolean coerced = rowTypeCoercion(scope, operand0, columnIndex,
targetType);
Review comment:
This will not fix the problem. Because when `rowTypeCoercion(scope,
operand0, columnIndex, targetType)=false`, `rowTypeCoercion(scope, operand1,
columnIndex, targetType) `will not be run.
I will use `|`, do you agree?
```
final boolean coerced = rowTypeCoercion(scope, operand0, columnIndex,
targetType)
| rowTypeCoercion(scope, operand1, columnIndex, targetType);
```
--
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]