Skip to content
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
17 changes: 9 additions & 8 deletions be/src/vec/exprs/lambda_function/varray_map_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@ class ArrayMapFunction : public LambdaFunction {
}

// here is the array column
const ColumnArray& col_array = assert_cast<const ColumnArray&>(*column_array);
const auto& col_array = assert_cast<const ColumnArray&>(*column_array);
const auto& col_type = assert_cast<const DataTypeArray&>(*type_array);

if (i == 0) {
nested_array_column_rows = col_array.get_data_ptr()->size();
first_array_offsets = col_array.get_offsets_ptr();
auto& off_data = assert_cast<const ColumnArray::ColumnOffsets&>(
const auto& off_data = assert_cast<const ColumnArray::ColumnOffsets&>(
col_array.get_offsets_column());
array_column_offset = off_data.clone_resized(col_array.get_offsets_column().size());
args.offsets_ptr = &col_array.get_offsets();
} else {
// select array_map((x,y)->x+y,c_array1,[0,1,2,3]) from array_test2;
// c_array1: [0,1,2,3,4,5,6,7,8,9]
auto& array_offsets =
const auto& array_offsets =
assert_cast<const ColumnArray::ColumnOffsets&>(*first_array_offsets)
.get_data();
if (nested_array_column_rows != col_array.get_data_ptr()->size() ||
Expand All @@ -198,9 +198,10 @@ class ArrayMapFunction : public LambdaFunction {

//process first row
args.array_start = (*args.offsets_ptr)[args.current_row_idx - 1];
args.cur_size = (*args.offsets_ptr)[args.current_row_idx] - args.array_start;

while (args.current_row_idx < block->rows()) {
args.cur_size = (*args.offsets_ptr).size()
? (*args.offsets_ptr)[args.current_row_idx] - args.array_start
: 0;
do {
Block lambda_block;
for (int i = 0; i < names.size(); i++) {
ColumnWithTypeAndName data_column;
Expand All @@ -220,7 +221,7 @@ class ArrayMapFunction : public LambdaFunction {
long current_step =
std::min(max_step, (long)(args.cur_size - args.current_offset_in_array));
size_t pos = args.array_start + args.current_offset_in_array;
for (int i = 0; i < arguments.size(); ++i) {
for (int i = 0; i < arguments.size() && current_step > 0; ++i) {
columns[gap + i]->insert_range_from(*lambda_datas[i], pos, current_step);
}
args.current_offset_in_array += current_step;
Expand Down Expand Up @@ -256,7 +257,7 @@ class ArrayMapFunction : public LambdaFunction {
MutableColumnPtr column = (*std::move(result_col)).mutate();
column->insert_range_from(*res_col, 0, res_col->size());
}
}
} while (args.current_row_idx < block->rows());

//4. get the result column after execution, reassemble it into a new array column, and return.
ColumnWithTypeAndName result_arr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,10 @@
1 [1, 2, 3, 4, 5] [10, 20, -40, 80, -100]
2 [6, 7, 8] [10, 12, 13]

-- !select_25 --
1 [[10, 20], [30, 40]]
2 [[50, 60], [70, 80]]
3 []
4 [[90, 100], [110, 120]]
5 [[130]]

Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,30 @@ suite("test_array_map_function") {
}

sql "DROP TABLE IF EXISTS ${tableName}"

sql "DROP TABLE IF EXISTS array_map_test"
sql """ CREATE TABLE IF NOT EXISTS array_map_test (
id INT,
int_array ARRAY<INT>,
string_array ARRAY<STRING>,
double_array ARRAY<DOUBLE>,
nested_array ARRAY<ARRAY<INT>>,
nullable_array ARRAY<INT> NULL
) ENGINE=OLAP
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);
"""
sql """ INSERT INTO array_map_test VALUES
(1, [1,2,3], ['a','b','c'], [1.1,2.2,3.3], [[1,2],[3,4]], NULL),
(2, [10,20], ['x','y'], [10.5,20.5], [[5,6],[7,8]], [1,2,3]),
(3, [], [], [], [], []),
(4, [100,200,300], ['one','two','three'], [100.1,200.2,300.3], [[9,10],[11,12]], [4,5,6]),
(5, [5], ['single'], [5.5], [[13]], [7]);
"""
qt_select_25 """
SELECT id, array_map(x -> array_map(y -> y * 10, x), nested_array) FROM array_map_test order by id;
"""
}
Loading