From 414c95a58b32fd9f7c349050729cc64c6f2ff922 Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Thu, 8 Feb 2024 14:42:25 +0800 Subject: [PATCH] [fix](function) incorrect result of 'equal_for_null' --- .../functions/comparison_equal_for_null.cpp | 2 +- .../correctness_p0/test_equal_for_null.out | 3 ++ .../correctness_p0/test_equal_for_null.groovy | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 regression-test/data/correctness_p0/test_equal_for_null.out create mode 100644 regression-test/suites/correctness_p0/test_equal_for_null.groovy diff --git a/be/src/vec/functions/comparison_equal_for_null.cpp b/be/src/vec/functions/comparison_equal_for_null.cpp index cf3384baa0eb70..561cd8f8aae298 100644 --- a/be/src/vec/functions/comparison_equal_for_null.cpp +++ b/be/src/vec/functions/comparison_equal_for_null.cpp @@ -76,7 +76,7 @@ class FunctionEqForNull : public IFunction { auto right_type_nullable = col_right.type->is_nullable(); if (!right_type_nullable) { block.get_by_position(result).column = - ColumnVector::create(input_rows_count); + ColumnVector::create(input_rows_count, 0); } else { auto const* nullable_right_col = assert_cast(col_right.column.get()); diff --git a/regression-test/data/correctness_p0/test_equal_for_null.out b/regression-test/data/correctness_p0/test_equal_for_null.out new file mode 100644 index 00000000000000..f958424e65c626 --- /dev/null +++ b/regression-test/data/correctness_p0/test_equal_for_null.out @@ -0,0 +1,3 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- + diff --git a/regression-test/suites/correctness_p0/test_equal_for_null.groovy b/regression-test/suites/correctness_p0/test_equal_for_null.groovy new file mode 100644 index 00000000000000..d2f04e8bdde0b4 --- /dev/null +++ b/regression-test/suites/correctness_p0/test_equal_for_null.groovy @@ -0,0 +1,50 @@ +// 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_equal_for_null") { + sql """ + DROP TABLE IF EXISTS `test_equal_for_null_tbl`; + """ + + sql """ + CREATE TABLE `test_equal_for_null_tbl` ( + `k1` int, + `k2` varchar(10), + `v1` varchar(1024), + `pk` int + ) + DISTRIBUTED BY HASH(`pk`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + insert into `test_equal_for_null_tbl`(`pk`,`k1`,`k2`,`v1`) values + (0,null,'y',"tell"), + (1,null,"his",'b'), + (2,null,"we",'g'), + (3,null,'n','t'), + (4,null,"were",'f'), + (5,null,"i",'q'), + (6,null,'f','g'), + (7,null,"time","are"), + (8,null,'k',"you"); + """ + + qt_select " select * from `test_equal_for_null_tbl` where `k1` <=> 4 order by 1, 2, 3, 4; " +} \ No newline at end of file