[bugfix] fix coredump caused by nullable const column compare to non-nullable const column (#11227)

This commit is contained in:
TengJianPing
2022-07-27 12:00:26 +08:00
committed by GitHub
parent 05b840fcb9
commit 2ed46eee64
5 changed files with 61 additions and 2 deletions

View File

@ -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<const ColumnConst&>(rhs).data,
nan_direction_hint);
auto rhs_const_column = assert_cast<const ColumnConst&>(rhs);
auto* this_nullable = check_and_get_column<ColumnNullable>(data.get());
auto* rhs_nullable = check_and_get_column<ColumnNullable>(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;

View File

@ -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

View File

@ -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

View File

@ -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';

View File

@ -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';