Skip to content

Commit

Permalink
[fix](Nereids): fix be core when array_map is not nullable (#24488) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
keanji-x authored Aug 1, 2024
1 parent 6c0fba4 commit 6ddca2a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 42 deletions.
64 changes: 28 additions & 36 deletions be/src/vec/exprs/lambda_function/varray_map_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ class ArrayMapFunction : public LambdaFunction {
"R" + array_column_type_name.name};
lambda_block.insert(std::move(data_column));
}
//check nullable(array(nullable(nested)))
DCHECK(result_type->is_nullable() &&
is_array(((DataTypeNullable*)result_type.get())->get_nested_type()))
<< "array_map result type is error, now must be nullable(array): "
<< result_type->get_name()
<< " ,and block structure is: " << block->dump_structure();

//3. child[0]->execute(new_block)
RETURN_IF_ERROR(children[0]->execute(context, &lambda_block, result_column_id));
Expand All @@ -155,40 +149,38 @@ class ArrayMapFunction : public LambdaFunction {

//4. get the result column after execution, reassemble it into a new array column, and return.
ColumnWithTypeAndName result_arr;
if (res_type->is_nullable()) {
result_arr = {ColumnNullable::create(
ColumnArray::create(res_col, std::move(array_column_offset)),
std::move(outside_null_map)),
result_type, res_name};

if (result_type->is_nullable()) {
if (res_type->is_nullable()) {
result_arr = {ColumnNullable::create(
ColumnArray::create(res_col, std::move(array_column_offset)),
std::move(outside_null_map)),
result_type, res_name};
} else {
// deal with eg: select array_map(x -> x is null, [null, 1, 2]);
// need to create the nested column null map for column array
auto nested_null_map = ColumnUInt8::create(res_col->size(), 0);
result_arr = {
ColumnNullable::create(
ColumnArray::create(
ColumnNullable::create(res_col, std::move(nested_null_map)),
std::move(array_column_offset)),
std::move(outside_null_map)),
result_type, res_name};
}
} else {
// deal with eg: select array_map(x -> x is null, [null, 1, 2]);
// need to create the nested column null map for column array
auto nested_null_map = ColumnUInt8::create(res_col->size(), 0);
result_arr = {ColumnNullable::create(
ColumnArray::create(ColumnNullable::create(
res_col, std::move(nested_null_map)),
std::move(array_column_offset)),
std::move(outside_null_map)),
result_type, res_name};
if (res_type->is_nullable()) {
result_arr = {ColumnArray::create(res_col, std::move(array_column_offset)),
result_type, res_name};
} else {
auto nested_null_map = ColumnUInt8::create(res_col->size(), 0);
result_arr = {ColumnArray::create(
ColumnNullable::create(res_col, std::move(nested_null_map)),
std::move(array_column_offset)),
result_type, res_name};
}
}
block->insert(std::move(result_arr));
*result_column_id = block->columns() - 1;
//check nullable(nested)
DCHECK((assert_cast<const DataTypeArray*>(
(((DataTypeNullable*)result_type.get())->get_nested_type().get())))
->get_nested_type()
->equals(*make_nullable(res_type)))
<< " array_map function FE given result type is: " << result_type->get_name()
<< " get nested is: "
<< (assert_cast<const DataTypeArray*>(
(((DataTypeNullable*)result_type.get())->get_nested_type().get())))
->get_nested_type()
->get_name()
<< " and now actual nested type after calculate " << res_type->get_name()
<< " ,and block structure is: " << block->dump_structure()
<< " ,and lambda_block structure is: " << lambda_block.dump_structure();

return Status::OK();
}
};
Expand Down
8 changes: 8 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,14 @@ private static boolean customNullableAlgorithm(Function fn, List<Expr> children)
if (fn.functionName().equalsIgnoreCase("array_sortby")) {
return children.get(0).isNullable();
}
if (fn.functionName().equalsIgnoreCase("array_map")) {
for (int i = 1; i < children.size(); ++i) {
if (children.get(i).isNullable()) {
return true;
}
}
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
+ lambda.debugString());
}
fn = new Function(fnName, Arrays.asList(argTypes), ArrayType.create(lambda.getChild(0).getType(), true),
true, true, NullableMode.DEPEND_ON_ARGUMENT);
true, true, NullableMode.CUSTOM);
} else if (fnName.getFunction().equalsIgnoreCase("array_exists")
|| fnName.getFunction().equalsIgnoreCase("array_first_index")
|| fnName.getFunction().equalsIgnoreCase("array_last_index")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public ArrayList<Expr> getSlotExprs() {
return slotExpr;
}

@Override
public boolean isNullable() {
for (int i = 1; i < slotExpr.size(); ++i) {
if (slotExpr.get(i).isNullable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.MarkJoinSlotReference;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.VirtualSlotReference;
import org.apache.doris.nereids.trees.expressions.SlotNotFromChildren;
import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
Expand Down Expand Up @@ -98,8 +97,7 @@ public static Optional<Slot> checkAllSlotFromChildren(Plan plan) {
.collect(Collectors.toSet());
Set<Slot> inputSlots = plan.getInputSlots();
for (Slot slot : inputSlots) {
if (slot instanceof MarkJoinSlotReference || slot instanceof VirtualSlotReference || slot.getName()
.startsWith("mv")) {
if (slot.getName().startsWith("mv") || slot instanceof SlotNotFromChildren) {
continue;
}
if (!(childOutputSet.contains(slot))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9713,4 +9713,3 @@ true
\N
\N
\N

0 comments on commit 6ddca2a

Please sign in to comment.