From fac1b2b1921532ecfc0e9e9eb9d1ce46087823c3 Mon Sep 17 00:00:00 2001 From: starocean999 <40539150+starocean999@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:06:06 +0800 Subject: [PATCH] [fix](planner)cast floating point type to bigint for bit functions (#26598) --- .../doris/analysis/FunctionCallExpr.java | 21 +++++++++++++++++++ .../data/correctness_p0/test_bit_function.out | 4 ++++ .../correctness_p0/test_bit_function.groovy | 21 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 regression-test/data/correctness_p0/test_bit_function.out create mode 100644 regression-test/suites/correctness_p0/test_bit_function.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 12e471979d..3a6751ad77 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1592,6 +1592,27 @@ public class FunctionCallExpr extends Expr { args[0] = Type.DOUBLE; System.arraycopy(childrenTypes, 1, args, 1, childrenTypes.length - 1); fn = getBuiltinFunction(fnName.getFunction(), args, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); + } else if (fnName.getFunction().equalsIgnoreCase("bitand") + || fnName.getFunction().equalsIgnoreCase("bitor") + || fnName.getFunction().equalsIgnoreCase("bitxor")) { + Type[] childTypes = collectChildReturnTypes(); + if (Arrays.stream(childTypes).anyMatch(child -> child.isDecimalV2() + || child.isDecimalV3() || child.isFloatingPointType())) { + uncheckedCastChild(Type.BIGINT, 0); + uncheckedCastChild(Type.BIGINT, 1); + argTypes[0] = Type.BIGINT; + argTypes[1] = Type.BIGINT; + } + fn = getBuiltinFunction(fnName.getFunction(), argTypes, + Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); + } else if (fnName.getFunction().equalsIgnoreCase("bitnot")) { + if (children.get(0).type.isDecimalV2() || children.get(0).type.isDecimalV3() + || children.get(0).type.isFloatingPointType()) { + uncheckedCastChild(Type.BIGINT, 0); + argTypes[0] = Type.BIGINT; + } + fn = getBuiltinFunction(fnName.getFunction(), argTypes, + Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); } else { // now first find table function in table function sets if (isTableFnCall) { diff --git a/regression-test/data/correctness_p0/test_bit_function.out b/regression-test/data/correctness_p0/test_bit_function.out new file mode 100644 index 0000000000..0fe60dde32 --- /dev/null +++ b/regression-test/data/correctness_p0/test_bit_function.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +64 123713 123649 -322 + diff --git a/regression-test/suites/correctness_p0/test_bit_function.groovy b/regression-test/suites/correctness_p0/test_bit_function.groovy new file mode 100644 index 0000000000..10b6e52de1 --- /dev/null +++ b/regression-test/suites/correctness_p0/test_bit_function.groovy @@ -0,0 +1,21 @@ +// 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_bit_functions") { + sql "SET enable_nereids_planner=false" + qt_select 'select bitand(123456, 321.0), bitor(123456, 321.0), bitxor(123456, 321.0), bitnot(321.0);' +}