diff --git a/be/src/vec/columns/column_const.h b/be/src/vec/columns/column_const.h index c63da6e29b..8a3646025f 100644 --- a/be/src/vec/columns/column_const.h +++ b/be/src/vec/columns/column_const.h @@ -21,6 +21,7 @@ #pragma once #include "vec/columns/column.h" +#include "vec/columns/column_nullable.h" #include "vec/common/assert_cast.h" #include "vec/common/exception.h" #include "vec/common/typeid_cast.h" @@ -144,8 +145,22 @@ public: size_t allocated_bytes() const override { return data->allocated_bytes() + sizeof(s); } int compare_at(size_t, size_t, const IColumn& rhs, int nan_direction_hint) const override { - return data->compare_at(0, 0, *assert_cast(rhs).data, - nan_direction_hint); + auto rhs_const_column = assert_cast(rhs); + + auto* this_nullable = check_and_get_column(data.get()); + auto* rhs_nullable = check_and_get_column(rhs_const_column.data.get()); + if (this_nullable && rhs_nullable) { + return data->compare_at(0, 0, *rhs_const_column.data, nan_direction_hint); + } else if (this_nullable) { + auto rhs_nullable_column = make_nullable(rhs_const_column.data, false); + return this_nullable->compare_at(0, 0, *rhs_nullable_column, nan_direction_hint); + } else if (rhs_nullable) { + auto this_nullable_column = make_nullable(data, false); + return this_nullable_column->compare_at(0, 0, *rhs_const_column.data, + nan_direction_hint); + } else { + return data->compare_at(0, 0, *rhs_const_column.data, nan_direction_hint); + } } MutableColumns scatter(ColumnIndex num_columns, const Selector& selector) const override; diff --git a/regression-test/data/correctness/sql/test_ifnull_function1.out b/regression-test/data/correctness/sql/test_ifnull_function1.out new file mode 100644 index 0000000000..ba9b10bdc7 --- /dev/null +++ b/regression-test/data/correctness/sql/test_ifnull_function1.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_ifnull_function1 -- +false + diff --git a/regression-test/data/correctness/sql/test_ifnull_function2.out b/regression-test/data/correctness/sql/test_ifnull_function2.out new file mode 100644 index 0000000000..3d52df1406 --- /dev/null +++ b/regression-test/data/correctness/sql/test_ifnull_function2.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_ifnull_function2 -- +true + diff --git a/regression-test/suites/correctness/sql/test_ifnull_function1.sql b/regression-test/suites/correctness/sql/test_ifnull_function1.sql new file mode 100644 index 0000000000..f082be6c6a --- /dev/null +++ b/regression-test/suites/correctness/sql/test_ifnull_function1.sql @@ -0,0 +1,18 @@ +-- 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. + +select IFNULL(get_json_string('{"k1":"v1", "k2":"v2"}', "$.k1"), 'SUCCESS')= 'FAIL'; diff --git a/regression-test/suites/correctness/sql/test_ifnull_function2.sql b/regression-test/suites/correctness/sql/test_ifnull_function2.sql new file mode 100644 index 0000000000..e330be6e8e --- /dev/null +++ b/regression-test/suites/correctness/sql/test_ifnull_function2.sql @@ -0,0 +1,18 @@ +-- 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. + +select IFNULL(get_json_string('{"k1":"FAIL", "k2":"v2"}', "$.k1"), 'SUCCESS')= 'FAIL';