Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement][Refactor] optimize array_contains_all/array_contains_seq function #51701

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions be/src/column/column_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ ColumnPtr ColumnHelper::convert_time_column_from_double_to_str(const ColumnPtr&
return res;
}

std::tuple<UInt32Column::Ptr, ColumnPtr, NullColumnPtr> ColumnHelper::unpack_array_column(const ColumnPtr& column) {
DCHECK(!column->is_nullable() && !column->is_constant());
DCHECK(column->is_array());

const ArrayColumn* array_column = down_cast<ArrayColumn*>(column.get());
auto elements_column = down_cast<NullableColumn*>(array_column->elements_column().get())->data_column();
auto null_column = down_cast<NullableColumn*>(array_column->elements_column().get())->null_column();
auto offsets_column = array_column->offsets_column();
return {offsets_column, elements_column, null_column};
}

template <class Ptr>
bool ChunkSliceTemplate<Ptr>::empty() const {
return !chunk || offset == chunk->num_rows();
Expand Down
3 changes: 3 additions & 0 deletions be/src/column/column_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ class ColumnHelper {
static ColumnPtr create_const_null_column(size_t chunk_size);

static ColumnPtr convert_time_column_from_double_to_str(const ColumnPtr& column);

// unpack array column, return offsets_column, elements_column, elements_null_column
static std::tuple<UInt32Column::Ptr, ColumnPtr, NullColumnPtr> unpack_array_column(const ColumnPtr& column);
};

// Hold a slice of chunk
Expand Down
32 changes: 32 additions & 0 deletions be/src/exprs/array_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,44 @@ class ArrayFunctions {
DEFINE_VECTORIZED_FN(array_cum_sum_double);

DEFINE_VECTORIZED_FN(array_contains_any);

DEFINE_VECTORIZED_FN(array_contains_all);

template <LogicalType LT>
static StatusOr<ColumnPtr> array_contains_all_specific(FunctionContext* context, const Columns& columns) {
return ArrayContainsAll<LT, false>::process(context, columns);
}
template <LogicalType LT>
static Status array_contains_all_specific_prepare(FunctionContext* context,
FunctionContext::FunctionStateScope scope) {
return ArrayContainsAll<LT, false>::prepare(context, scope);
}
template <LogicalType LT>
static Status array_contains_all_specific_close(FunctionContext* context,
FunctionContext::FunctionStateScope scope) {
return ArrayContainsAll<LT, false>::close(context, scope);
}

DEFINE_VECTORIZED_FN(array_map);
DEFINE_VECTORIZED_FN(array_filter);
DEFINE_VECTORIZED_FN(all_match);
DEFINE_VECTORIZED_FN(any_match);

DEFINE_VECTORIZED_FN(array_contains_seq);
template <LogicalType LT>
static StatusOr<ColumnPtr> array_contains_seq_specific(FunctionContext* context, const Columns& columns) {
return ArrayContainsAll<LT, true>::process(context, columns);
}
template <LogicalType LT>
static Status array_contains_seq_specific_prepare(FunctionContext* context,
FunctionContext::FunctionStateScope scope) {
return ArrayContainsAll<LT, true>::prepare(context, scope);
}
template <LogicalType LT>
static Status array_contains_seq_specific_close(FunctionContext* context,
FunctionContext::FunctionStateScope scope) {
return ArrayContainsAll<LT, true>::close(context, scope);
}

// array function for nested type(Array/Map/Struct)
DEFINE_VECTORIZED_FN(array_distinct_any_type);
Expand Down
Loading
Loading