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

Method parseQuery

src/Client/ClientBase.cpp:454–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452}
453
454ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, const Settings & settings, bool allow_multi_statements)
455{
456 std::unique_ptr<IParserBase> parser;
457 ASTPtr res;
458
459 size_t max_length = 0;
460
461 if (!allow_multi_statements)
462 max_length = settings[Setting::max_query_size];
463
464 const Dialect dialect = settings[Setting::dialect];
465
466 if (dialect == Dialect::kusto)
467 parser = std::make_unique<ParserKQLStatement>(end, settings[Setting::allow_settings_after_format_in_insert]);
468 else if (dialect == Dialect::prql)
469 parser = std::make_unique<ParserPRQLQuery>(max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
470 else if (dialect == Dialect::promql)
471 parser = std::make_unique<ParserPrometheusQuery>(settings[Setting::promql_database], settings[Setting::promql_table], Field{settings[Setting::promql_evaluation_time]});
472 else if (dialect == Dialect::polyglot)
473 parser = std::make_unique<ParserPolyglotQuery>(max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks], settings[Setting::polyglot_dialect], end, settings[Setting::allow_experimental_polyglot_dialect]);
474 else
475 parser = std::make_unique<ParserQuery>(end, settings[Setting::allow_settings_after_format_in_insert], settings[Setting::implicit_select]);
476
477 if (is_interactive || ignore_error)
478 {
479 String message;
480 try
481 {
482 if (dialect == Dialect::kusto)
483 res = tryParseKQLQuery(*parser, pos, end, message, nullptr, true, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks], true);
484 else
485 res = tryParseQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks], true);
486 }
487 catch (const Exception & e)
488 {
489 error_stream << "Exception on client:" << std::endl << getExceptionMessage(e, print_stack_trace, true) << std::endl << std::endl;
490 client_exception.reset(e.clone());
491 return nullptr;
492 }
493
494 if (!res)
495 {
496 error_stream << std::endl << message << std::endl << std::endl;
497 return nullptr;
498 }
499 }
500 else
501 {
502 if (dialect == Dialect::kusto)
503 res = parseKQLQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
504 else
505 res = parseQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
506 }
507
508 return res;
509}
510
511

Callers

nothing calls this directly

Calls 7

tryParseKQLQueryFunction · 0.85
tryParseQueryFunction · 0.85
getExceptionMessageFunction · 0.50
resetMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected