From 55fdb555bea637d53a375d00a04b3d88ae246274 Mon Sep 17 00:00:00 2001 From: TengJianPing <18241664+jacktengg@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:07:48 +0800 Subject: [PATCH] [bugfix](dict) fix coredump of dict colum range predicate when there is null value (#11967) --- be/src/vec/columns/column_dictionary.h | 9 +++- .../test_dict_range_predicate.out | 7 +++ .../test_dict_range_predicate.groovy | 47 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 regression-test/data/correctness_p0/test_dict_range_predicate.out create mode 100644 regression-test/suites/correctness_p0/test_dict_range_predicate.groovy diff --git a/be/src/vec/columns/column_dictionary.h b/be/src/vec/columns/column_dictionary.h index fcc24d253d..8a6cc0c905 100644 --- a/be/src/vec/columns/column_dictionary.h +++ b/be/src/vec/columns/column_dictionary.h @@ -296,7 +296,7 @@ public: return -2; // -1 is null code } - T get_null_code() { return -1; } + T get_null_code() const { return -1; } inline StringValue& get_value(T code) { return code >= _dict_data.size() ? _null_value : _dict_data[code]; @@ -391,7 +391,12 @@ public: } } - T convert_code(const T& code) const { return _code_convert_table[code]; } + T convert_code(const T& code) const { + if (get_null_code() == code) { + return code; + } + return _code_convert_table[code]; + } size_t byte_size() { return _dict_data.size() * sizeof(_dict_data[0]); } diff --git a/regression-test/data/correctness_p0/test_dict_range_predicate.out b/regression-test/data/correctness_p0/test_dict_range_predicate.out new file mode 100644 index 0000000000..fe5d70316e --- /dev/null +++ b/regression-test/data/correctness_p0/test_dict_range_predicate.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_default -- +4 d + +-- !select_default -- +1 a +3 c diff --git a/regression-test/suites/correctness_p0/test_dict_range_predicate.groovy b/regression-test/suites/correctness_p0/test_dict_range_predicate.groovy new file mode 100644 index 0000000000..c35c27982d --- /dev/null +++ b/regression-test/suites/correctness_p0/test_dict_range_predicate.groovy @@ -0,0 +1,47 @@ +// 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_dict_range_predicate") { + def tableName = "test_dict_range_predicate" + + sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ + CREATE TABLE ${tableName} ( + `a` int, + `b` char(10) + ) ENGINE=OLAP + DUPLICATE KEY(`a`) + DISTRIBUTED BY HASH(`a`) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + + sql "insert into ${tableName} values (1, 'a'), (2, null), (3, 'c'), (4, 'd');" + + qt_select_default """ + select * + from ${tableName} WHERE b > 'c' order by a + """ + + qt_select_default """ + select * + from ${tableName} WHERE b <= 'c' order by a + """ + }