From 2a6be1f4ae6130f3a3c5d2efad96a44aa44cee55 Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:02:04 +0800 Subject: [PATCH] [fix](Nereids) processCharacterLiteral even if both side are literal (#36729) pick from master #36729 --- .../doris/nereids/util/TypeCoercionUtils.java | 4 ---- .../test_string_literal_vs_other_literal.out | 11 +++++++++ ...est_string_literal_vs_other_literal.groovy | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 regression-test/data/nereids_p0/type_inference/test_string_literal_vs_other_literal.out create mode 100644 regression-test/suites/nereids_p0/type_inference/test_string_literal_vs_other_literal.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java index e6dcca83a8bc6f..0bbd11007a0d7a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java @@ -505,10 +505,6 @@ public static T processCharacterLiteralInBinaryOperat if (!(left instanceof Literal) && !(right instanceof Literal)) { return (T) op.withChildren(left, right); } - if (left instanceof Literal && right instanceof Literal) { - // process by constant folding - return (T) op.withChildren(left, right); - } if (left instanceof Literal && ((Literal) left).isStringLikeLiteral() && !right.getDataType().isStringLikeType()) { left = TypeCoercionUtils.characterLiteralTypeCoercion( diff --git a/regression-test/data/nereids_p0/type_inference/test_string_literal_vs_other_literal.out b/regression-test/data/nereids_p0/type_inference/test_string_literal_vs_other_literal.out new file mode 100644 index 00000000000000..788187beebad88 --- /dev/null +++ b/regression-test/data/nereids_p0/type_inference/test_string_literal_vs_other_literal.out @@ -0,0 +1,11 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !numeric_eq -- +1 + +-- !numeric_non_eq -- + +-- !date_eq -- +1 + +-- !date_eq -- + diff --git a/regression-test/suites/nereids_p0/type_inference/test_string_literal_vs_other_literal.groovy b/regression-test/suites/nereids_p0/type_inference/test_string_literal_vs_other_literal.groovy new file mode 100644 index 00000000000000..43ad242de0722d --- /dev/null +++ b/regression-test/suites/nereids_p0/type_inference/test_string_literal_vs_other_literal.groovy @@ -0,0 +1,24 @@ +// 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_string_literal_vs_other_literal") { + qt_numeric_eq """select 1 where "12345678901234567890" = 12345678901234567890;""" + qt_numeric_non_eq """select 1 where "12345678901234567890" = 12345678901234567891;""" + + qt_date_eq """select 1 where "2024-06-24 00:01:02.345678" = cast("2024-06-24 00:01:02.345678" as datetime(6)) """ + qt_date_eq """select 1 where "2024-06-24 00:01:02.345679" = cast("2024-06-24 00:01:02.345678" as datetime(6)) """ +}