diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java index ba86efa138..264b956700 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java @@ -27,6 +27,7 @@ import org.apache.doris.analysis.Expr; import org.apache.doris.analysis.IntLiteral; import org.apache.doris.analysis.LiteralExpr; import org.apache.doris.analysis.SlotRef; +import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; @@ -123,6 +124,7 @@ public class RewriteBinaryPredicatesRule implements ExprRewriteRule { if (expr0 instanceof CastExpr && (expr0.getType() == Type.DECIMALV2 || expr0.getType().isDecimalV3()) && expr0.getChild(0) instanceof SlotRef && expr0.getChild(0).getType().getResultType() == Type.BIGINT + && expr0.getChild(0).getType().getPrimitiveType() != PrimitiveType.BOOLEAN && expr1 instanceof DecimalLiteral) { return rewriteBigintSlotRefCompareDecimalLiteral(expr0, expr0.getChild(0).getType(), (DecimalLiteral) expr1, op); diff --git a/regression-test/data/cast_decimal_to_boolean/test_cast_decimal_to_boolean.out b/regression-test/data/cast_decimal_to_boolean/test_cast_decimal_to_boolean.out new file mode 100644 index 0000000000..7e0ee1649a --- /dev/null +++ b/regression-test/data/cast_decimal_to_boolean/test_cast_decimal_to_boolean.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +false +false +true diff --git a/regression-test/suites/cast_decimal_to_boolean/test_cast_decimal_to_boolean.groovy b/regression-test/suites/cast_decimal_to_boolean/test_cast_decimal_to_boolean.groovy new file mode 100644 index 0000000000..2638a3a1f6 --- /dev/null +++ b/regression-test/suites/cast_decimal_to_boolean/test_cast_decimal_to_boolean.groovy @@ -0,0 +1,29 @@ +// 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_decimal_to_boolean") { + def tableName = "tbl_test_decimal_to_boolean" + sql "DROP TABLE IF EXISTS ${tableName}" + sql "CREATE TABLE if NOT EXISTS ${tableName} (c0 BOOLEAN NOT NULL) DUPLICATE KEY(c0) DISTRIBUTED BY HASH (c0) BUCKETS 1 PROPERTIES ('replication_num' = '1');" + sql """insert into ${tableName} values (1), + (0), + (0)""" + + qt_select " select (c0 BETWEEN 0.44 AND 1) from ${tableName} order by 1" + + sql "DROP TABLE IF EXISTS ${tableName}" +}