diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index b8dc17d546..540f8821f5 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -1066,24 +1066,9 @@ public class ScalarType extends Type { return createVarcharType(Math.max(t1.len, t2.len)); } - if (t1.isDecimalV2() && t2.isDate() - || t1.isDate() && t2.isDecimalV2()) { - return INVALID; - } - - if ((t1.isDecimalV2() && t2.isDateV2()) - || (t1.isDateV2() && t2.isDecimalV2())) { - return INVALID; - } - - if ((t1.isDecimalV3() && t2.isDate()) - || (t1.isDate() && t2.isDecimalV3())) { - return INVALID; - } - - if ((t1.isDecimalV3() && t2.isDateV2()) - || (t1.isDateV2() && t2.isDecimalV3())) { - return INVALID; + if (((t1.isDecimalV3() || t1.isDecimalV2()) && (t2.isDateV2() || t2.isDate())) + || ((t2.isDecimalV3() || t2.isDecimalV2()) && (t1.isDateV2() || t1.isDate()))) { + return Type.DOUBLE; } if (t1.isDecimalV2() && t2.isDecimalV2()) { diff --git a/regression-test/data/correctness_p0/test_cast_date_decimal.out b/regression-test/data/correctness_p0/test_cast_date_decimal.out new file mode 100644 index 0000000000..5b10e282f2 --- /dev/null +++ b/regression-test/data/correctness_p0/test_cast_date_decimal.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +true + diff --git a/regression-test/suites/correctness_p0/test_cast_date_decimal.groovy b/regression-test/suites/correctness_p0/test_cast_date_decimal.groovy new file mode 100644 index 0000000000..a2d00c05ef --- /dev/null +++ b/regression-test/suites/correctness_p0/test_cast_date_decimal.groovy @@ -0,0 +1,26 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_cast_date_decimal") { + sql """ + set enable_nereids_planner=false; + """ + + qt_sql """ + select cast('2020-02-02' as date ) between cast('2020-02-02' as date ) and cast('2020-02-02' as date ) + 1.0; + """ +}