Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ public boolean isTimeV2() {
return isScalarType(PrimitiveType.TIMEV2);
}

public boolean isTimeLikeType() {
return isTimeV2() || isTime();
}

public boolean isWildcardDecimal() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class CastExpr extends Expr {
TYPE_NULLABLE_MODE.put(Pair.of(fromType, toType), Function.NullableMode.ALWAYS_NULLABLE);
} else if (!fromType.isDateType() && toType.isDateType()) {
TYPE_NULLABLE_MODE.put(Pair.of(fromType, toType), Function.NullableMode.ALWAYS_NULLABLE);
} else if (!fromType.isTimeLikeType() && toType.isTimeLikeType()) {
TYPE_NULLABLE_MODE.put(Pair.of(fromType, toType), Function.NullableMode.ALWAYS_NULLABLE);
} else {
TYPE_NULLABLE_MODE.put(Pair.of(fromType, toType), Function.NullableMode.DEPEND_ON_ARGUMENT);
}
Expand Down Expand Up @@ -571,7 +573,8 @@ private int getDigital(String desc, List<String> parameters, List<Expr> inputPar
public boolean isNullable() {
return children.get(0).isNullable()
|| (children.get(0).getType().isStringType() && !getType().isStringType())
|| (!children.get(0).getType().isDateType() && getType().isDateType());
|| (!children.get(0).getType().isDateType() && getType().isDateType())
|| (!children.get(0).getType().isTimeLikeType() && getType().isTimeLikeType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.doris.nereids.types.LargeIntType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TimeType;
import org.apache.doris.nereids.types.TimeV2Type;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;
import org.apache.doris.nereids.util.ExpressionUtils;
Expand Down Expand Up @@ -64,6 +66,8 @@ public class Coalesce extends ScalarFunction
FunctionSignature.ret(DateTimeType.INSTANCE).varArgs(DateTimeType.INSTANCE),
FunctionSignature.ret(DateV2Type.INSTANCE).varArgs(DateV2Type.INSTANCE),
FunctionSignature.ret(DateType.INSTANCE).varArgs(DateType.INSTANCE),
FunctionSignature.ret(TimeType.INSTANCE).varArgs(TimeType.INSTANCE),
FunctionSignature.ret(TimeV2Type.INSTANCE).varArgs(TimeV2Type.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).varArgs(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).varArgs(DecimalV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(BitmapType.INSTANCE).varArgs(BitmapType.INSTANCE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.doris.nereids.types.NullType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TimeType;
import org.apache.doris.nereids.types.TimeV2Type;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;
import org.apache.doris.nereids.util.TypeCoercionUtils;
Expand Down Expand Up @@ -85,7 +87,12 @@ public class If extends ScalarFunction
.args(BooleanType.INSTANCE, DoubleType.INSTANCE, DoubleType.INSTANCE),
FunctionSignature.ret(DateTimeType.INSTANCE)
.args(BooleanType.INSTANCE, DateTimeType.INSTANCE, DateTimeType.INSTANCE),
FunctionSignature.ret(DateType.INSTANCE).args(BooleanType.INSTANCE, DateType.INSTANCE, DateType.INSTANCE),
FunctionSignature.ret(DateType.INSTANCE).args(BooleanType.INSTANCE, DateType.INSTANCE,
DateType.INSTANCE),
FunctionSignature.ret(TimeType.INSTANCE).args(BooleanType.INSTANCE, TimeType.INSTANCE,
TimeType.INSTANCE),
FunctionSignature.ret(TimeV2Type.INSTANCE).args(BooleanType.INSTANCE, TimeV2Type.INSTANCE,
TimeV2Type.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD)
.args(BooleanType.INSTANCE, DecimalV3Type.WILDCARD, DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.apache.doris.nereids.types.LargeIntType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TimeType;
import org.apache.doris.nereids.types.TimeV2Type;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;

Expand Down Expand Up @@ -65,6 +67,8 @@ public class NullIf extends ScalarFunction
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE, DateV2Type.INSTANCE),
FunctionSignature.ret(TimeType.INSTANCE).args(TimeType.INSTANCE, TimeType.INSTANCE),
FunctionSignature.ret(TimeV2Type.INSTANCE).args(TimeV2Type.INSTANCE, TimeV2Type.INSTANCE),
FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT)
.args(DecimalV2Type.SYSTEM_DEFAULT, DecimalV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(DecimalV3Type.WILDCARD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.doris.nereids.types.LargeIntType;
import org.apache.doris.nereids.types.SmallIntType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.types.TimeType;
import org.apache.doris.nereids.types.TimeV2Type;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.types.VarcharType;

Expand Down Expand Up @@ -66,7 +68,11 @@ public class Nvl extends ScalarFunction
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
.args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(DateV2Type.INSTANCE)
.args(DateV2Type.INSTANCE, DateV2Type.INSTANCE),
.args(DateV2Type.INSTANCE, DateV2Type.INSTANCE),
FunctionSignature.ret(TimeType.INSTANCE)
.args(TimeType.INSTANCE, TimeType.INSTANCE),
FunctionSignature.ret(TimeV2Type.INSTANCE)
.args(TimeV2Type.INSTANCE, TimeV2Type.INSTANCE),
FunctionSignature.ret(BitmapType.INSTANCE).args(BitmapType.INSTANCE, BitmapType.INSTANCE),
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
.args(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
-- !sql3 --
4.41

-- !sql4 --
00:01:23 00:01:23 00:01:23 00:01:23

-- !sql5 --
00:01:23 00:01:23 00:01:23 00:01:23

Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ suite("test_case_when_decimal") {

sql """ DROP TABLE IF EXISTS `decimal_to_double_table1`; """
sql """ DROP TABLE IF EXISTS `decimal_to_double_table2`; """


qt_sql4 """
select ifnull(cast(123 as time) , cast(300 as time)) , coalesce(cast(123 as time) , cast(300 as time)) , if(true ,cast(123 as time) , cast(300 as time)) , nullif(cast(123 as time) , cast(300 as time));
"""


qt_sql5 """
select ifnull(cast(123 as time) , cast(300 as time)) , coalesce(cast(123 as time) , cast(300 as time)) , if(true ,cast(123 as time) , cast(300 as time)) , nullif(cast(123 as time) , cast(300 as time));
"""
}