Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCALAR_TABLE_FUNCTION: add mapping vector #55

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Conversation

Tishj
Copy link
Owner

@Tishj Tishj commented Aug 4, 2023

		// Any other vector type: we need to create a selection vector
		// but can avoid flattening because the memory of the selection vector will not be temporary
		AddProjectedColumnsFromOtherMapping(base_columns, input, intermediate_chunk, chunk);
		break;


void PhysicalTableInOutFunction::AddProjectedColumnsFromOtherMapping(idx_t map_idx, DataChunk &input,
                                                                     DataChunk &intermediate, DataChunk &out) const {
	auto &mapping_column = intermediate.data[map_idx];

	SelectionVector sel_vec;
	sel_vec.Initialize(intermediate.size());
	// Create a selection vector that maps from output row -> input row
	UnifiedVectorFormat mapping_vector_data;
	mapping_column.ToUnifiedFormat(intermediate.size(), mapping_vector_data);
	auto mapping_data = reinterpret_cast<sel_t *>(mapping_vector_data.data);
	for (idx_t i = 0; i < intermediate.size(); i++) {
		// The index in the input column that produced this output tuple
		idx_t idx = mapping_vector_data.sel->get_index(i);
		const auto input_row = mapping_data[idx];
		D_ASSERT(input_row < STANDARD_VECTOR_SIZE);
		sel_vec.set_index(i, input_row);
	}

	// Add the projected columns, and apply the selection vector
	for (idx_t project_idx = 0; project_idx < projected_input.size(); project_idx++) {
		auto source_idx = projected_input[project_idx];
		D_ASSERT(source_idx < input.data.size());
		auto target_idx = map_idx + project_idx;

		auto &target_column = out.data[target_idx];
		auto &source_column = input.data[source_idx];

		target_column.Slice(source_column, sel_vec, intermediate.size());
		// Note: we can avoid flattening this
	}
}

Tishj added 24 commits March 7, 2023 17:24
… vector type of produced mapping vector in UNNEST to constant - since we only emit one unnested row at a time
@github-actions github-actions bot marked this pull request as draft August 14, 2023 13:02
@Tishj Tishj changed the title Scalar table function SCALAR_TABLE_FUNCTION: add mapping vector Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant