MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / buildCommonHeaderForUnion

Function buildCommonHeaderForUnion

src/Planner/Utils.cpp:107–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107Block buildCommonHeaderForUnion(const SharedHeaders & queries_headers, SelectUnionMode union_mode, bool use_variant_as_common_type)
108{
109 size_t num_selects = queries_headers.size();
110 Block common_header = *queries_headers.front();
111 size_t columns_size = common_header.columns();
112
113 for (size_t query_number = 1; query_number < num_selects; ++query_number)
114 {
115 int error_code = 0;
116
117 if (union_mode == SelectUnionMode::UNION_DEFAULT ||
118 union_mode == SelectUnionMode::UNION_ALL ||
119 union_mode == SelectUnionMode::UNION_DISTINCT)
120 error_code = ErrorCodes::UNION_ALL_RESULT_STRUCTURES_MISMATCH;
121 else
122 error_code = ErrorCodes::INTERSECT_OR_EXCEPT_RESULT_STRUCTURES_MISMATCH;
123
124 if (queries_headers.at(query_number)->columns() != columns_size)
125 throw Exception(error_code,
126 "Different number of columns in {} elements: {} and {}",
127 toString(union_mode),
128 common_header.dumpNames(),
129 queries_headers[query_number]->dumpNames());
130 }
131
132 VectorWithMemoryTracking<const ColumnWithTypeAndName *> columns(num_selects);
133
134 for (size_t column_number = 0; column_number < columns_size; ++column_number)
135 {
136 for (size_t i = 0; i < num_selects; ++i)
137 columns[i] = &queries_headers[i]->getByPosition(column_number);
138
139 ColumnWithTypeAndName & result_element = common_header.getByPosition(column_number);
140 result_element = getLeastSuperColumn(columns, use_variant_as_common_type);
141 }
142
143 return common_header;
144}
145
146void addConvertingToCommonHeaderActionsIfNeeded(
147 std::vector<std::unique_ptr<QueryPlan>> & query_plans,

Callers 2

decorrelateQueryPlanFunction · 0.85
buildPlanForUnionNodeMethod · 0.85

Calls 8

getLeastSuperColumnFunction · 0.85
columnsMethod · 0.80
ExceptionClass · 0.50
toStringFunction · 0.50
sizeMethod · 0.45
frontMethod · 0.45
atMethod · 0.45
dumpNamesMethod · 0.45

Tested by

no test coverage detected