Skip to content

Commit

Permalink
[Bug](array) fix array column core dump in get_shrinked_column as not…
Browse files Browse the repository at this point in the history
… check type (#33295)

* [Bug](array) fix array column core dump in get_shrinked_column as not check type

* add function could_shrinked_column
  • Loading branch information
zhangstar333 authored and Doris-Extras committed Apr 7, 2024
1 parent 1b3e432 commit ebbfb06
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 10 deletions.
6 changes: 5 additions & 1 deletion be/src/vec/columns/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ class IColumn : public COW<IColumn> {

// shrink the end zeros for CHAR type or ARRAY<CHAR> type
virtual MutablePtr get_shrinked_column() {
LOG(FATAL) << "Cannot clone_resized() column " << get_name();
LOG(FATAL) << "Cannot get_shrinked_column() column " << get_name();
return nullptr;
}

// check the column whether could shrinked
// now support only in char type, or the nested type in complex type: array{char}, struct{char}, map{char}
virtual bool could_shrinked_column() { return false; }

/// Some columns may require finalization before using of other operations.
virtual void finalize() {}

Expand Down
10 changes: 9 additions & 1 deletion be/src/vec/columns/column_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ ColumnArray::ColumnArray(MutableColumnPtr&& nested_column) : data(std::move(nest
offsets = ColumnOffsets::create();
}

bool ColumnArray::could_shrinked_column() {
return data->could_shrinked_column();
}

MutableColumnPtr ColumnArray::get_shrinked_column() {
return ColumnArray::create(data->get_shrinked_column(), offsets->assume_mutable());
if (could_shrinked_column()) {
return ColumnArray::create(data->get_shrinked_column(), offsets->assume_mutable());
} else {
return ColumnArray::create(data->assume_mutable(), offsets->assume_mutable());
}
}

std::string ColumnArray::get_name() const {
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/columns/column_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ColumnArray final : public COWHelper<IColumn, ColumnArray> {
}

MutableColumnPtr get_shrinked_column() override;
bool could_shrinked_column() override;

/** On the index i there is an offset to the beginning of the i + 1 -th element. */
using ColumnOffsets = ColumnVector<Offset64>;
Expand Down
10 changes: 6 additions & 4 deletions be/src/vec/columns/column_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,20 @@ ColumnPtr ColumnMap::replicate(const Offsets& offsets) const {
return res;
}

bool ColumnMap::could_shrinked_column() {
return keys_column->could_shrinked_column() || values_column->could_shrinked_column();
}

MutableColumnPtr ColumnMap::get_shrinked_column() {
MutableColumns new_columns(2);

if (keys_column->is_column_string() || keys_column->is_column_array() ||
keys_column->is_column_map() || keys_column->is_column_struct()) {
if (keys_column->could_shrinked_column()) {
new_columns[0] = keys_column->get_shrinked_column();
} else {
new_columns[0] = keys_column->get_ptr();
}

if (values_column->is_column_string() || values_column->is_column_array() ||
values_column->is_column_map() || values_column->is_column_struct()) {
if (values_column->could_shrinked_column()) {
new_columns[1] = values_column->get_shrinked_column();
} else {
new_columns[1] = values_column->get_ptr();
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/columns/column_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ColumnMap final : public COWHelper<IColumn, ColumnMap> {

void update_hash_with_value(size_t n, SipHash& hash) const override;
MutableColumnPtr get_shrinked_column() override;
bool could_shrinked_column() override;
ColumnPtr filter(const Filter& filt, ssize_t result_size_hint) const override;
size_t filter(const Filter& filter) override;
ColumnPtr permute(const Permutation& perm, size_t limit) const override;
Expand Down
12 changes: 10 additions & 2 deletions be/src/vec/columns/column_nullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ ColumnNullable::ColumnNullable(MutableColumnPtr&& nested_column_, MutableColumnP
_need_update_has_null = true;
}

bool ColumnNullable::could_shrinked_column() {
return get_nested_column_ptr()->could_shrinked_column();
}

MutableColumnPtr ColumnNullable::get_shrinked_column() {
return ColumnNullable::create(get_nested_column_ptr()->get_shrinked_column(),
get_null_map_column_ptr());
if (could_shrinked_column()) {
return ColumnNullable::create(get_nested_column_ptr()->get_shrinked_column(),
get_null_map_column_ptr());
} else {
return ColumnNullable::create(get_nested_column_ptr(), get_null_map_column_ptr());
}
}

void ColumnNullable::update_xxHash_with_value(size_t start, size_t end, uint64_t& hash,
Expand Down
2 changes: 2 additions & 0 deletions be/src/vec/columns/column_nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
}

MutableColumnPtr get_shrinked_column() override;
bool could_shrinked_column() override;
bool is_variable_length() const override { return nested_column->is_variable_length(); }

const char* get_family_name() const override { return "Nullable"; }
std::string get_name() const override { return "Nullable(" + nested_column->get_name() + ")"; }
MutableColumnPtr clone_resized(size_t size) const override;
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/columns/column_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class ColumnString final : public COWHelper<IColumn, ColumnString> {
MutableColumnPtr clone_resized(size_t to_size) const override;

MutableColumnPtr get_shrinked_column() override;
bool could_shrinked_column() override { return true; }

Field operator[](size_t n) const override {
assert(n < size());
Expand Down
13 changes: 11 additions & 2 deletions be/src/vec/columns/column_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,22 @@ ColumnPtr ColumnStruct::replicate(const Offsets& offsets) const {
return ColumnStruct::create(new_columns);
}

bool ColumnStruct::could_shrinked_column() {
const size_t tuple_size = columns.size();
for (size_t i = 0; i < tuple_size; ++i) {
if (columns[i]->could_shrinked_column()) {
return true;
}
}
return false;
}

MutableColumnPtr ColumnStruct::get_shrinked_column() {
const size_t tuple_size = columns.size();
MutableColumns new_columns(tuple_size);

for (size_t i = 0; i < tuple_size; ++i) {
if (columns[i]->is_column_string() || columns[i]->is_column_array() ||
columns[i]->is_column_map() || columns[i]->is_column_struct()) {
if (columns[i]->could_shrinked_column()) {
new_columns[i] = columns[i]->get_shrinked_column();
} else {
new_columns[i] = columns[i]->get_ptr();
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/columns/column_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class ColumnStruct final : public COWHelper<IColumn, ColumnStruct> {
int compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const override;

MutableColumnPtr get_shrinked_column() override;
bool could_shrinked_column() override;

void reserve(size_t n) override;
void resize(size_t n) override;
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/query_p0/test_array_orderby_limit.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
-- !select --
100 [["abc"]]

-- !select_2 --
a {"codes": [123, 456], "props": {"key1":["char1", "char2"]}}

16 changes: 16 additions & 0 deletions regression-test/suites/query_p0/test_array_orderby_limit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,20 @@ suite("test_array_char_orderby", "query") {
}

qt_select """ select * from ${testTable} order by k1 limit 1 """

sql "DROP TABLE IF EXISTS unpart_tbl_parquet_struct_3;"
sql """
CREATE TABLE unpart_tbl_parquet_struct_3 (
`col1` CHAR,
`col20` STRUCT<codes:ARRAY<INT>,props:MAP<STRING, ARRAY<CHAR(16)>>>
)ENGINE=OLAP
DUPLICATE KEY(`col1`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`col1`) BUCKETS 5
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""
sql """ insert into unpart_tbl_parquet_struct_3 values ('a',STRUCT(ARRAY(123, 456), MAP('key1', ARRAY('char1', 'char2'))) ); """
qt_select_2 """ select * from unpart_tbl_parquet_struct_3;"""
}

0 comments on commit ebbfb06

Please sign in to comment.