[
https://issues.apache.org/jira/browse/FLINK-33541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17788263#comment-17788263
]
xuyang edited comment on FLINK-33541 at 11/21/23 6:05 AM:
----------------------------------------------------------
The root cause is that in 1.14, the cast rule allow to cast from 'int' to 'int
nullable'. However in 1.15, the new built-in cast rule has more strict
restrictions on this situation. The difference about code can be found as
follows.
1.14: PlannerTypeUtils
{code:java}
/**
* Can the two types operate with each other. Such as: 1.CodeGen: equal, cast,
assignment.
* 2.Join keys.
*/
public static boolean isInteroperable(LogicalType t1, LogicalType t2) {
if (t1.getTypeRoot().getFamilies().contains(CHARACTER_STRING)
&& t2.getTypeRoot().getFamilies().contains(CHARACTER_STRING)) {
return true;
}
if (t1.getTypeRoot().getFamilies().contains(BINARY_STRING)
&& t2.getTypeRoot().getFamilies().contains(BINARY_STRING)) {
return true;
}
if (t1.getTypeRoot() != t2.getTypeRoot()) {
return false;
}
switch (t1.getTypeRoot()) {
case ARRAY:
case MAP:
case MULTISET:
case ROW:
List<LogicalType> children1 = t1.getChildren();
List<LogicalType> children2 = t2.getChildren();
if (children1.size() != children2.size()) {
return false;
}
for (int i = 0; i < children1.size(); i++) {
if (!isInteroperable(children1.get(i), children2.get(i))) {
return false;
}
}
return true;
default:
return t1.copy(true).equals(t2.copy(true)); // difference
}
} {code}
1.15: NumericPrimitiveCastRule
{code:java}
private static boolean matches(LogicalType input, LogicalType target) {
// Exclude identity casting
if (input.is(target.getTypeRoot())) { // difference
return false;
}
// Conversions between primitive numerics
if ((input.is(INTEGER_NUMERIC) || input.is(APPROXIMATE_NUMERIC))
&& (target.is(INTEGER_NUMERIC) || target.is(APPROXIMATE_NUMERIC))) {
return true;
}
// Conversions between Interval year month (int) and bigint (long)
if ((input.is(INTERVAL_YEAR_MONTH) && target.is(BIGINT))
|| (input.is(BIGINT) && target.is(INTERVAL_YEAR_MONTH))) {
return true;
}
// Conversions between Interval day time (long) and integer (int)
if ((input.is(INTERVAL_DAY_TIME) && target.is(INTEGER))
|| (input.is(INTEGER) && target.is(INTERVAL_DAY_TIME))) {
return true;
}
// Conversions from tinyint/smallint to Interval day time
if ((input.is(TINYINT) || input.is(SMALLINT)) &&
target.is(INTERVAL_DAY_TIME)) {
return true;
}
// Conversions from tinyint/smallint to Interval year month
return (input.is(TINYINT) || input.is(SMALLINT)) &&
target.is(INTERVAL_YEAR_MONTH);
} {code}
was (Author: xuyangzhong):
The root cause is that in 1.14, the cast rule allow to cast from 'int' to 'int
nullable'. However in 1.15, the new built-in cast rule has more strict
restrictions on this situation. The difference about code can be found as
follows.
1.14: CastRuleProvider
!image-2023-11-21-14-00-51-975.png|width=465,height=516!
1.15: NumericPrimitiveCastRule
!image-2023-11-21-14-02-34-837.png|width=469,height=473!
> RAND_INTEGER can't be existed in a IF statement
> ------------------------------------------------
>
> Key: FLINK-33541
> URL: https://issues.apache.org/jira/browse/FLINK-33541
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / API
> Affects Versions: 1.17.0, 1.18.0
> Reporter: Guojun Li
> Priority: Major
>
> The minimum produce steps:
> Flink SQL> select if(1=1, rand_integer(100), 0);
> [ERROR] Could not execute SQL statement. Reason:
> java.lang.Exception: Unsupported operand types: IF(boolean, INT, INT NOT NULL)
>
> But we do not see the exception reported in 1.14, not sure which version this
> bug was introduced.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)