Skip to content

Commit e6fecab

Browse files
committed
[vectorized](function) add some check about result type in array map #19228
1 parent 8cfb970 commit e6fecab

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

be/src/vec/exprs/lambda_function/lambda_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LambdaFunction {
3232
virtual std::string get_name() const = 0;
3333

3434
virtual doris::Status execute(VExprContext* context, doris::vectorized::Block* block,
35-
int* result_column_id, DataTypePtr result_type,
35+
int* result_column_id, const DataTypePtr& result_type,
3636
const std::vector<VExpr*>& children) = 0;
3737
};
3838

be/src/vec/exprs/lambda_function/varray_filter_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ArrayFilterFunction : public LambdaFunction {
4242
std::string get_name() const override { return name; }
4343

4444
doris::Status execute(VExprContext* context, doris::vectorized::Block* block,
45-
int* result_column_id, DataTypePtr result_type,
45+
int* result_column_id, const DataTypePtr& result_type,
4646
const std::vector<VExpr*>& children) override {
4747
///* array_filter(array, array<boolean>) *///
4848

be/src/vec/exprs/lambda_function/varray_map_function.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ArrayMapFunction : public LambdaFunction {
4040
std::string get_name() const override { return name; }
4141

4242
doris::Status execute(VExprContext* context, doris::vectorized::Block* block,
43-
int* result_column_id, DataTypePtr result_type,
43+
int* result_column_id, const DataTypePtr& result_type,
4444
const std::vector<VExpr*>& children) override {
4545
///* array_map(lambda,arg1,arg2,.....) *///
4646

@@ -118,6 +118,12 @@ class ArrayMapFunction : public LambdaFunction {
118118
"R" + array_column_type_name.name};
119119
lambda_block.insert(std::move(data_column));
120120
}
121+
//check nullable(array(nullable(nested)))
122+
DCHECK(result_type->is_nullable() &&
123+
is_array(((DataTypeNullable*)result_type.get())->get_nested_type()))
124+
<< "array_map result type is error, now must be nullable(array): "
125+
<< result_type->get_name()
126+
<< " ,and block structure is: " << block->dump_structure();
121127

122128
//3. child[0]->execute(new_block)
123129
RETURN_IF_ERROR(children[0]->execute(context, &lambda_block, result_column_id));
@@ -136,6 +142,7 @@ class ArrayMapFunction : public LambdaFunction {
136142
result_type, res_name};
137143

138144
} else {
145+
// deal with eg: select array_map(x -> x is null, [null, 1, 2]);
139146
// need to create the nested column null map for column array
140147
auto nested_null_map = ColumnUInt8::create(res_col->size(), 0);
141148
result_arr = {ColumnNullable::create(
@@ -147,6 +154,21 @@ class ArrayMapFunction : public LambdaFunction {
147154
}
148155
block->insert(std::move(result_arr));
149156
*result_column_id = block->columns() - 1;
157+
//check nullable(nested)
158+
DCHECK((assert_cast<const DataTypeArray*>(
159+
(((DataTypeNullable*)result_type.get())->get_nested_type().get())))
160+
->get_nested_type()
161+
->equals(*make_nullable(res_type)))
162+
<< " array_map function FE given result type is: " << result_type->get_name()
163+
<< " get nested is: "
164+
<< (assert_cast<const DataTypeArray*>(
165+
(((DataTypeNullable*)result_type.get())->get_nested_type().get())))
166+
->get_nested_type()
167+
->get_name()
168+
<< " and now actual nested type after calculate " << res_type->get_name()
169+
<< " ,and block structure is: " << block->dump_structure()
170+
<< " ,and lambda_block structure is: " << lambda_block.dump_structure();
171+
150172
return Status::OK();
151173
}
152174
};

gensrc/script/doris_builtins_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@
619619
[['array_popfront'], 'ARRAY_DECIMAL128', ['ARRAY_DECIMAL128'], ''],
620620
[['array_popfront'], 'ARRAY_VARCHAR', ['ARRAY_VARCHAR'], ''],
621621
[['array_popfront'], 'ARRAY_STRING', ['ARRAY_STRING'], ''],
622-
[['array_map'], 'ARRAY', ['LAMBDA_FUNCTION', 'ARRAY', '...'], ''],
622+
[['array_map'], 'ARRAY', ['LAMBDA_FUNCTION', 'ARRAY<K>', '...'], '', ['K']],
623623
[['array_filter'], 'ARRAY_BOOLEAN',['ARRAY_BOOLEAN', 'ARRAY_BOOLEAN'], ''],
624624
[['array_filter'], 'ARRAY_TINYINT',['ARRAY_TINYINT', 'ARRAY_BOOLEAN'], ''],
625625
[['array_filter'], 'ARRAY_SMALLINT',['ARRAY_SMALLINT', 'ARRAY_BOOLEAN'], ''],

0 commit comments

Comments
 (0)