Skip to content

Commit

Permalink
[Enhancement][Refactor] optimize array_contains_all/array_contains_se…
Browse files Browse the repository at this point in the history
…q function (#51701)

Signed-off-by: silverbullet233 <[email protected]>
(cherry picked from commit ac623b3)

# Conflicts:
#	be/src/column/column_helper.h
#	be/src/exprs/array_functions.h
#	be/src/exprs/array_functions.tpp
#	be/src/util/bit_mask.h
#	fe/fe-core/src/main/java/com/starrocks/catalog/FunctionSet.java
#	gensrc/script/functions.py
#	test/sql/test_array_fn/R/test_array_contains
#	test/sql/test_array_fn/T/test_array_contains
  • Loading branch information
silverbullet233 authored and mergify[bot] committed Oct 22, 2024
1 parent 3faf7d4 commit eb1c68b
Show file tree
Hide file tree
Showing 10 changed files with 1,680 additions and 2 deletions.
11 changes: 11 additions & 0 deletions be/src/column/column_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,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
5 changes: 5 additions & 0 deletions be/src/column/column_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,14 @@ class ColumnHelper {

static ColumnPtr convert_time_column_from_double_to_str(const ColumnPtr& column);

<<<<<<< HEAD
static NullColumnPtr one_size_not_null_column;

static NullColumnPtr one_size_null_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);
>>>>>>> ac623b3de5 ([Enhancement][Refactor] optimize array_contains_all/array_contains_seq function (#51701))
};

// Hold a slice of chunk
Expand Down
36 changes: 36 additions & 0 deletions be/src/exprs/array_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,47 @@ 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);
<<<<<<< HEAD
=======

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);
}
>>>>>>> ac623b3de5 ([Enhancement][Refactor] optimize array_contains_all/array_contains_seq function (#51701))

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

0 comments on commit eb1c68b

Please sign in to comment.