[feature-wip](array-type) support explode and explode_outer table function (#8766)

explode(ArrayColumn) desc:
> Create a row for each element in the array column. 

explode_outer(ArrayColumn) desc:
> Create a row for each element in the array column. Unlike explode, if the array is null or empty, it returns null.

Usage example:
1. create a table with array column, and insert some data;
2. open enable_lateral_view and enable_vectorized_engine;
```
set enable_lateral_view = true;
set enable_vectorized_engine=true;
```
3. use explode_outer
```
> select * from array_test;
+------+------+--------+
| k1   | k2   | k3     |
+------+------+--------+
|    3 | NULL | NULL   |
|    1 |    2 | [1, 2] |
|    2 |    3 | NULL   |
|    4 | NULL | []     |
+------+------+--------+

> select k1,explode_column from array_test LATERAL VIEW explode_outer(k3) TempExplodeView as explode_column;
+------+----------------+
| k1   | explode_column |
+------+----------------+
|    1 |              1 |
|    1 |              2 |
|    2 |           NULL |
|    4 |           NULL |
|    3 |           NULL |
+------+----------------+
```
4. explode usage example. explode return empty rows while the ARRAY is null or empty
```
> select k1,explode_column from array_test LATERAL VIEW explode(k3) TempExplodeView as explode_column;
+------+----------------+
| k1   | explode_column |
+------+----------------+
|    1 |              1 |
|    1 |              2 |
+------+----------------+
```
This commit is contained in:
camby
2022-04-08 12:11:04 +08:00
committed by GitHub
parent bd0a3369b7
commit c5718928df
19 changed files with 677 additions and 78 deletions

View File

@ -92,6 +92,16 @@ Status VTableFunctionNode::get_next(RuntimeState* state, Block* block, bool* eos
return Status::OK();
}
bool VTableFunctionNode::_is_inner_and_empty() {
for (int i = 0; i < _fn_num; i++) {
// if any table function is not outer and has empty result, go to next child row
if (!_fns[i]->is_outer() && _fns[i]->current_empty()) {
return true;
}
}
return false;
}
Status VTableFunctionNode::get_expanded_block(RuntimeState* state, Block* output_block, bool* eos) {
DCHECK(_child_block != nullptr);
@ -128,9 +138,10 @@ Status VTableFunctionNode::get_expanded_block(RuntimeState* state, Block* output
RETURN_IF_ERROR(_process_next_child_row());
}
bool skip_child_row = false;
while (true) {
int idx = _find_last_fn_eos_idx();
if (idx == 0) {
if (idx == 0 || skip_child_row) {
// all table functions' results are exhausted, process next child row.
RETURN_IF_ERROR(_process_next_child_row());
if (_cur_child_offset == -1) {
@ -144,6 +155,11 @@ Status VTableFunctionNode::get_expanded_block(RuntimeState* state, Block* output
}
}
// if any table function is not outer and has empty result, go to next child row
if ((skip_child_row = _is_inner_and_empty()) == true) {
continue;
}
// get slots from every table function.
// notice that _fn_values[i] may be null if the table function has empty result set.
for (int i = 0; i < _fn_num; i++) {