[fix](table-function) Fix bug of table function with outer join cause nullptr of tuple (#9041)

This commit is contained in:
HappenLee
2022-04-18 19:35:26 +08:00
committed by GitHub
parent f3dce9a6c1
commit 51db4e54c0
3 changed files with 38 additions and 14 deletions

View File

@ -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<Tuple*>(reinterpret_cast<uint8_t*>(tuple_ptr) +
parent_tuple_desc->byte_size());
}

View File

@ -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

View File

@ -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 """