HappenLee commented on code in PR #62069:
URL: https://github.com/apache/doris/pull/62069#discussion_r3031838882
##########
be/src/exec/operator/table_function_operator.cpp:
##########
@@ -264,30 +266,135 @@ Status
TableFunctionLocalState::_get_expanded_block_block_fast_path(
const auto& offsets = *_block_fast_path_ctx.offsets_ptr;
const auto child_rows = cast_set<int64_t>(offsets.size());
- std::vector<uint32_t> row_ids;
- row_ids.reserve(remaining_capacity);
- uint64_t first_nested_idx = 0;
- uint64_t expected_next_nested_idx = 0;
- bool found_nested_range = false;
-
int64_t child_row = _block_fast_path_row;
uint64_t in_row_offset = _block_fast_path_in_row_offset;
int produced_rows = 0;
- while (produced_rows < remaining_capacity && child_row < child_rows) {
- if (_block_fast_path_ctx.array_nullmap_data &&
- _block_fast_path_ctx.array_nullmap_data[child_row]) {
- // NULL array row: skip it here. Slow path will handle output
semantics if needed.
- child_row++;
- in_row_offset = 0;
- continue;
+ const bool is_outer = _fns[0]->is_outer();
+ const bool is_posexplode = _block_fast_path_ctx.generate_row_index;
+ auto& out_col = columns[p._child_slots.size()];
+
+ // Decompose posexplode struct output column if needed
+ ColumnStruct* struct_col_ptr = nullptr;
+ ColumnUInt8* outer_struct_nullmap_ptr = nullptr;
+ IColumn* value_col_ptr = nullptr;
+ ColumnInt32* pos_col_ptr = nullptr;
+ if (is_posexplode) {
+ if (out_col->is_nullable()) {
+ auto* nullable = assert_cast<ColumnNullable*>(out_col.get());
+ struct_col_ptr =
assert_cast<ColumnStruct*>(nullable->get_nested_column_ptr().get());
+ outer_struct_nullmap_ptr =
+
assert_cast<ColumnUInt8*>(nullable->get_null_map_column_ptr().get());
+ } else {
+ struct_col_ptr = assert_cast<ColumnStruct*>(out_col.get());
+ }
+ pos_col_ptr =
assert_cast<ColumnInt32*>(&struct_col_ptr->get_column(0));
+ value_col_ptr = &struct_col_ptr->get_column(1);
+ }
+ // Segment tracking: accumulate contiguous nested ranges, flush on
boundaries.
+ // Array column offsets are monotonically non-decreasing, so nested data
across child rows
+ // is always contiguous (even with NULL/empty rows that contribute zero
elements).
+ std::vector<uint32_t> seg_row_ids;
+ std::vector<int32_t> seg_positions; // for posexplode
+ int64_t seg_nested_start = -1;
+ int seg_nested_count = 0;
+ seg_row_ids.reserve(remaining_capacity);
+ if (is_posexplode) {
+ seg_positions.reserve(remaining_capacity);
+ }
+
+ // Flush accumulated contiguous segment to output columns
+ auto flush_segment = [&]() {
+ if (seg_nested_count == 0) {
+ return;
+ }
+
+ // Non-TF columns: replicate each child row for every output element
+ for (auto index : p._output_slot_indexs) {
+ auto src_column = _child_block->get_by_position(index).column;
+ columns[index]->insert_indices_from(*src_column,
seg_row_ids.data(),
+ seg_row_ids.data() +
seg_row_ids.size());
}
+ if (is_posexplode) {
+ // Write positions
+ for (auto pos : seg_positions) {
Review Comment:
这里应该批量插入吧?insert_many_raw_data better?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]