diff --git a/be/src/exec/table_function_node.cpp b/be/src/exec/table_function_node.cpp index ee225a0610..aeeb17e05c 100644 --- a/be/src/exec/table_function_node.cpp +++ b/be/src/exec/table_function_node.cpp @@ -273,23 +273,29 @@ Status TableFunctionNode::get_next(RuntimeState* state, RowBatch* row_batch, boo Tuple* child_tuple = _cur_child_tuple_row->get_tuple( child_rowdesc.get_tuple_idx(child_tuple_desc->id())); - // copy the child tuple to parent_tuple - memcpy(tuple_ptr, child_tuple, parent_tuple_desc->byte_size()); - // only deep copy the child slot if it is selected and is var len (Eg: string, bitmap, hll) - for (int j = 0; j < _child_slot_sizes[i]; ++j) { - SlotDescriptor* child_slot_desc = child_tuple_desc->slots()[j]; - SlotDescriptor* parent_slot_desc = parent_tuple_desc->slots()[j]; + // The child tuple is nullptr, only when the child tuple is from outer join. so we directly set + // parent_tuple have same tuple_idx nullptr to mock the behavior + if (child_tuple != nullptr) { + // copy the child tuple to parent_tuple + memcpy(tuple_ptr, child_tuple, parent_tuple_desc->byte_size()); + // only deep copy the child slot if it is selected and is var len (Eg: string, bitmap, hll) + for (int j = 0; j < _child_slot_sizes[i]; ++j) { + SlotDescriptor *child_slot_desc = child_tuple_desc->slots()[j]; + SlotDescriptor *parent_slot_desc = parent_tuple_desc->slots()[j]; - if (_output_slot_ids[parent_slot_desc->id()] && - !child_tuple->is_null(child_slot_desc->null_indicator_offset()) - && child_slot_desc->type().is_string_type()) { - void* dest_slot = tuple_ptr->get_slot(parent_slot_desc->tuple_offset()); - RawValue::write(child_tuple->get_slot(child_slot_desc->tuple_offset()), - dest_slot, parent_slot_desc->type(), - row_batch->tuple_data_pool()); + if (_output_slot_ids[parent_slot_desc->id()] && + !child_tuple->is_null(child_slot_desc->null_indicator_offset()) + && child_slot_desc->type().is_string_type()) { + void *dest_slot = tuple_ptr->get_slot(parent_slot_desc->tuple_offset()); + RawValue::write(child_tuple->get_slot(child_slot_desc->tuple_offset()), + dest_slot, parent_slot_desc->type(), + row_batch->tuple_data_pool()); + } } + parent_tuple_row->set_tuple(tuple_idx, tuple_ptr); + } else { + parent_tuple_row->set_tuple(tuple_idx, nullptr); } - parent_tuple_row->set_tuple(tuple_idx, tuple_ptr); tuple_ptr = reinterpret_cast(reinterpret_cast(tuple_ptr) + parent_tuple_desc->byte_size()); } diff --git a/regression-test/data/table_function/explode_json_array.out b/regression-test/data/table_function/explode_json_array.out index 60696b758b..120c4e0297 100644 --- a/regression-test/data/table_function/explode_json_array.out +++ b/regression-test/data/table_function/explode_json_array.out @@ -65,6 +65,20 @@ 400 Dan 50 4 Street 4 22.214 b 400 Dan 50 4 Street 4 214.1 b +-- !outer_join_explode_json_array -- +\N \N 1 +\N \N 3 +\N \N b +\N 30 1 +\N 30 3 +\N 30 b +\N 50 1 +\N 50 3 +\N 50 b +\N 80 1 +\N 80 3 +\N 80 b + -- !explode_json_array -- true diff --git a/regression-test/suites/table_function/explode_json_array.groovy b/regression-test/suites/table_function/explode_json_array.groovy index 9460101ea7..3aacc1ee46 100644 --- a/regression-test/suites/table_function/explode_json_array.groovy +++ b/regression-test/suites/table_function/explode_json_array.groovy @@ -58,6 +58,10 @@ suite("explode_json_array") { LATERAL VIEW EXPLODE_JSON_ARRAY_DOUBLE('[1.23, 22.214, 214.1]') t2 as d ORDER BY id, c, d """ + qt_outer_join_explode_json_array """SELECT id, age, e1 FROM (SELECT id, age, e1 FROM (SELECT b.id, a.age FROM + ${tableName} a LEFT JOIN ${tableName} b ON a.id=b.age)T LATERAL VIEW EXPLODE_JSON_ARRAY_STRING('[1, "b", 3]') + TMP AS e1) AS T ORDER BY age, e1""" + // vectorized sql """ set enable_vectorized_engine = true """