[feature-wip](array-type) explode support more sub types (#10673)
1. explode support more sub types; 2. explode support nullable elements; Co-authored-by: cambyzju <zhuxiaoli01@baidu.com>
This commit is contained in:
@ -27,24 +27,16 @@ VExplodeTableFunction::VExplodeTableFunction() {
|
||||
|
||||
Status VExplodeTableFunction::process_init(vectorized::Block* block) {
|
||||
CHECK(_vexpr_context->root()->children().size() == 1)
|
||||
<< "VExplodeTableFunction must be have 1 children but have "
|
||||
<< "VExplodeTableFunction only support 1 child but has "
|
||||
<< _vexpr_context->root()->children().size();
|
||||
|
||||
int value_column_idx = -1;
|
||||
_vexpr_context->root()->children()[0]->execute(_vexpr_context, block, &value_column_idx);
|
||||
|
||||
if (block->get_by_position(value_column_idx).column->is_nullable()) {
|
||||
auto array_nullable_column = check_and_get_column<ColumnNullable>(
|
||||
*block->get_by_position(value_column_idx).column);
|
||||
_array_null_map = array_nullable_column->get_null_map_column().get_data().data();
|
||||
_array_column =
|
||||
check_and_get_column<ColumnArray>(array_nullable_column->get_nested_column_ptr());
|
||||
} else {
|
||||
_array_null_map = nullptr;
|
||||
_array_column =
|
||||
check_and_get_column<ColumnArray>(*block->get_by_position(value_column_idx).column);
|
||||
}
|
||||
if (!_array_column) {
|
||||
_array_column =
|
||||
block->get_by_position(value_column_idx).column->convert_to_full_column_if_const();
|
||||
|
||||
if (!extract_column_array_info(*_array_column, _detail)) {
|
||||
return Status::NotSupported("column type {} not supported now",
|
||||
block->get_by_position(value_column_idx).column->get_name());
|
||||
}
|
||||
@ -56,26 +48,22 @@ Status VExplodeTableFunction::process_row(size_t row_idx) {
|
||||
DCHECK(row_idx < _array_column->size());
|
||||
_is_current_empty = false;
|
||||
_eos = false;
|
||||
_cur_offset = 0;
|
||||
_array_offset = (*_detail.offsets_ptr)[row_idx - 1];
|
||||
_cur_size = (*_detail.offsets_ptr)[row_idx] - _array_offset;
|
||||
|
||||
if (_array_null_map && _array_null_map[row_idx]) {
|
||||
// array is NULL, or array is empty
|
||||
if (_cur_size == 0 || (_detail.array_nullmap_data && _detail.array_nullmap_data[row_idx])) {
|
||||
_is_current_empty = true;
|
||||
_cur_size = 0;
|
||||
_cur_offset = 0;
|
||||
_pos = 0;
|
||||
} else {
|
||||
_cur_size =
|
||||
_array_column->get_offsets()[row_idx] - _array_column->get_offsets()[row_idx - 1];
|
||||
_cur_offset = 0;
|
||||
_is_current_empty = (_cur_size == 0);
|
||||
_pos = _array_column->get_offsets()[row_idx - 1];
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status VExplodeTableFunction::process_close() {
|
||||
_array_column = nullptr;
|
||||
_array_null_map = nullptr;
|
||||
_pos = 0;
|
||||
_detail.reset();
|
||||
_array_offset = 0;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -91,7 +79,13 @@ Status VExplodeTableFunction::get_value(void** output) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
*output = const_cast<char*>(_array_column->get_data().get_data_at(_pos + _cur_offset).data);
|
||||
size_t pos = _array_offset + _cur_offset;
|
||||
if (_detail.nested_nullmap_data && _detail.nested_nullmap_data[pos]) {
|
||||
*output = nullptr;
|
||||
} else {
|
||||
*output = const_cast<char*>(_detail.nested_col->get_data_at(pos).data);
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -101,7 +95,13 @@ Status VExplodeTableFunction::get_value_length(int64_t* length) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
*length = _array_column->get_data().get_data_at(_pos + _cur_offset).size;
|
||||
size_t pos = _array_offset + _cur_offset;
|
||||
if (_detail.nested_nullmap_data && _detail.nested_nullmap_data[pos]) {
|
||||
*length = 0;
|
||||
} else {
|
||||
*length = _detail.nested_col->get_data_at(pos).size;
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user