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

Method parseImpl

src/Parsers/PRQL/ParserPRQLQuery.cpp:25–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25bool ParserPRQLQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
26{
27 ParserSetQuery set_p;
28
29 if (set_p.parse(pos, node, expected))
30 return true;
31
32#if !USE_PRQL
33 throw Exception(
34 ErrorCodes::SUPPORT_IS_DISABLED, "PRQL is not available. Rust code or PRQL itself may be disabled. Use another dialect!");
35#else
36 const auto * begin = pos->begin;
37
38 // The same parsers are used in the client and the server, so the parser have to detect the end of a single query in case of multiquery queries
39 while (!pos->isEnd() && pos->type != TokenType::Semicolon)
40 ++pos;
41
42 const auto * end = pos->begin;
43
44 uint8_t * sql_query_ptr{nullptr};
45 uint64_t sql_query_size{0};
46
47 const auto res
48 = prql_to_sql(reinterpret_cast<const uint8_t *>(begin), static_cast<uint64_t>(end - begin), &sql_query_ptr, &sql_query_size);
49
50 SCOPE_EXIT({ prql_free_pointer(sql_query_ptr); });
51
52 const auto * sql_query_char_ptr = reinterpret_cast<char *>(sql_query_ptr);
53 const auto * const original_sql_query_ptr = sql_query_char_ptr;
54
55 if (res != 0)
56 {
57 throw Exception(ErrorCodes::SYNTAX_ERROR, "PRQL syntax error: '{}'", sql_query_char_ptr);
58 }
59 chassert(sql_query_size > 0);
60
61 ParserQuery query_p(end, false);
62 String error_message;
63 node = tryParseQuery(
64 query_p,
65 sql_query_char_ptr,
66 sql_query_char_ptr + sql_query_size - 1,
67 error_message,
68 false,
69 "",
70 false,
71 max_query_size,
72 max_parser_depth,
73 max_parser_backtracks,
74 true);
75
76 if (!node)
77 throw Exception(
78 ErrorCodes::SYNTAX_ERROR,
79 "Error while parsing the SQL query generated from PRQL query :'{}'.\nPRQL Query:'{}'\nSQL query: '{}'",
80 error_message,
81 std::string_view{begin, end},
82 std::string_view(original_sql_query_ptr, original_sql_query_ptr + sql_query_size));

Callers

nothing calls this directly

Calls 7

prql_to_sqlFunction · 0.85
prql_free_pointerFunction · 0.85
tryParseQueryFunction · 0.85
string_viewClass · 0.85
ExceptionClass · 0.50
parseMethod · 0.45
isEndMethod · 0.45

Tested by

no test coverage detected