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

Method buildSelectExpression

src/Analyzer/QueryTreeBuilder.cpp:262–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262QueryTreeNodePtr QueryTreeBuilder::buildSelectExpression(
263 const ASTPtr & select_query,
264 bool is_subquery,
265 const CommonTableExpressionData & cte_data,
266 const ASTPtr & aliases,
267 const ContextPtr & context) const
268{
269 const auto & select_query_typed = select_query->as<ASTSelectQuery &>();
270
271 auto updated_context = Context::createCopy(context);
272 auto select_settings = select_query_typed.settings();
273 SettingsChanges settings_changes;
274
275 /// We are going to remove settings LIMIT and OFFSET and
276 /// further replace them with corresponding expression nodes
277 UInt64 limit = 0;
278 UInt64 offset = 0;
279
280 /// Remove global settings limit and offset
281 if (const auto & settings_ref = updated_context->getSettingsRef(); settings_ref[Setting::limit] || settings_ref[Setting::offset])
282 {
283 Settings settings = updated_context->getSettingsCopy();
284 limit = settings[Setting::limit];
285 offset = settings[Setting::offset];
286 settings[Setting::limit] = 0;
287 settings[Setting::offset] = 0;
288 updated_context->setSettings(settings);
289 }
290
291 if (select_settings)
292 {
293 auto & set_query = select_settings->as<ASTSetQuery &>();
294
295 /// Remove expression settings limit and offset
296 if (auto * limit_field = set_query.changes.tryGet("limit"))
297 {
298 limit = limit_field->safeGet<UInt64>();
299 set_query.changes.removeSetting("limit");
300 }
301 if (auto * offset_field = set_query.changes.tryGet("offset"))
302 {
303 offset = offset_field->safeGet<UInt64>();
304 set_query.changes.removeSetting("offset");
305 }
306
307 if (!set_query.changes.empty())
308 {
309 updated_context->applySettingsChanges(set_query.changes);
310 settings_changes = set_query.changes;
311 }
312 }
313
314 const auto enable_order_by_all = updated_context->getSettingsRef()[Setting::enable_order_by_all];
315
316 auto current_query_tree = std::make_shared<QueryNode>(std::move(updated_context), std::move(settings_changes));
317
318 current_query_tree->setIsSubquery(is_subquery);
319 current_query_tree->setIsCTE(!cte_data.cte_name.empty());

Callers

nothing calls this directly

Calls 15

settingsMethod · 0.80
getSettingsCopyMethod · 0.80
removeSettingMethod · 0.80
setIsRecursiveWithMethod · 0.80
setIsDistinctMethod · 0.80
setIsLimitWithTiesMethod · 0.80
setIsGroupByWithCubeMethod · 0.80
setIsGroupByAllMethod · 0.80
setIsOrderByAllMethod · 0.80

Tested by

no test coverage detected