|
11 | 11 | #include <Parsers/ASTLiteral.h> |
12 | 12 | #include <Parsers/ParserCreateQuery.h> |
13 | 13 | #include <Parsers/Streaming/ParserArguments.h> |
| 14 | +#include <Parsers/ParserKeyValuePairsSet.h> |
14 | 15 |
|
15 | 16 | #include <Poco/JSON/Object.h> |
16 | 17 | /// proton: ends |
@@ -40,11 +41,14 @@ bool ParserCreateFunctionQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Exp |
40 | 41 | ParserKeyword s_auth_method("AUTH_METHOD"); |
41 | 42 | ParserKeyword s_auth_header("AUTH_HEADER"); |
42 | 43 | ParserKeyword s_auth_key("AUTH_KEY"); |
| 44 | + ParserKeyword s_execution_timeout("EXECUTION_TIMEOUT"); |
43 | 45 | ParserLiteral value; |
| 46 | + ASTPtr kv_list; |
44 | 47 | ASTPtr url; |
45 | 48 | ASTPtr auth_method; |
46 | 49 | ASTPtr auth_header; |
47 | 50 | ASTPtr auth_key; |
| 51 | + ASTPtr execution_timeout; |
48 | 52 | ParserArguments arguments_p; |
49 | 53 | ParserDataType return_p; |
50 | 54 | ParserStringLiteral js_src_p; |
@@ -139,35 +143,74 @@ bool ParserCreateFunctionQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Exp |
139 | 143 | { |
140 | 144 | throw Exception("Remote udf can not be an aggregate function", ErrorCodes::AGGREGATE_FUNCTION_NOT_APPLICABLE); |
141 | 145 | } |
142 | | - if (!s_url.ignore(pos, expected)) |
| 146 | + ParserKeyValuePairsSet kv_pairs_list; |
| 147 | + if (!kv_pairs_list.parse(pos, kv_list, expected)) |
143 | 148 | return false; |
144 | | - if (!value.parse(pos, url, expected)) |
145 | | - return false; |
146 | | - if (s_auth_method.ignore(pos, expected)) |
| 149 | + |
| 150 | + /// check if the parameters are valid and no unsupported or unknown parameters. |
| 151 | + std::optional<String> ast_url; |
| 152 | + std::optional<String> ast_auth_method; |
| 153 | + std::optional<String> ast_auth_header; |
| 154 | + std::optional<String> ast_auth_key; |
| 155 | + std::optional<UInt64> ast_execution_timeout; |
| 156 | + for (const auto & kv : kv_list->children) |
| 157 | + { |
| 158 | + auto * kv_pair = kv->as<ASTPair>(); |
| 159 | + auto key = kv_pair->first; |
| 160 | + auto pair_value = kv_pair->second->as<ASTLiteral>()->value; |
| 161 | + if (!kv_pair) |
| 162 | + throw Exception("Key-value pair expected", ErrorCodes::UNKNOWN_FUNCTION); |
| 163 | + |
| 164 | + if (key == "url") |
| 165 | + { |
| 166 | + ast_url = pair_value.safeGet<String>(); |
| 167 | + } |
| 168 | + else if (key == "auth_method") |
| 169 | + { |
| 170 | + ast_auth_method = pair_value.safeGet<String>(); |
| 171 | + if (ast_auth_method.value() != "none" && ast_auth_method.value() != "auth_header") |
| 172 | + throw Exception("Unknown auth method", ErrorCodes::UNKNOWN_FUNCTION); |
| 173 | + } |
| 174 | + else if (key == "auth_header") |
| 175 | + { |
| 176 | + ast_auth_header = pair_value.safeGet<String>(); |
| 177 | + } |
| 178 | + else if (key == "auth_key") |
| 179 | + { |
| 180 | + ast_auth_key = pair_value.safeGet<String>(); |
| 181 | + } |
| 182 | + else if (key == "execution_timeout") |
| 183 | + { |
| 184 | + ast_execution_timeout = pair_value.safeGet<UInt64>(); |
| 185 | + } |
| 186 | + } |
| 187 | + /// check if URL is set |
| 188 | + if (!ast_url) |
| 189 | + throw Exception("URL is required for remote function", ErrorCodes::UNKNOWN_FUNCTION); |
| 190 | + /// check if auth_method is "auth_header" or "none" |
| 191 | + if (ast_auth_method) |
147 | 192 | { |
148 | | - if (!value.parse(pos, auth_method, expected)) |
149 | | - return false; |
150 | | - auto method_str = auth_method->as<ASTLiteral>()->value.safeGet<String>(); |
151 | | - url->children.push_back(std::move(auth_method)); |
152 | | - if (method_str == "auth_header") |
| 193 | + if (ast_auth_method.value() == "auth_header") |
153 | 194 | { |
154 | | - if (!s_auth_header.ignore(pos, expected)) |
155 | | - return false; |
156 | | - if (!value.parse(pos, auth_header, expected)) |
157 | | - return false; |
158 | | - if (!s_auth_key.ignore(pos, expected)) |
159 | | - return false; |
160 | | - if (!value.parse(pos, auth_key, expected)) |
161 | | - return false; |
162 | | - url->children.push_back(std::move(auth_header)); |
163 | | - url->children.push_back(std::move(auth_key)); |
| 195 | + if (!ast_auth_header || !ast_auth_key) |
| 196 | + throw Exception("Auth header and auth key are required for auth_header auth method", ErrorCodes::UNKNOWN_FUNCTION); |
164 | 197 | } |
165 | | - else if (method_str != "none") |
| 198 | + else if (ast_auth_method.value() == "none") |
166 | 199 | { |
167 | | - throw Exception("AUTH_METHOD must be 'none' or 'auth_header'", ErrorCodes::UNKNOWN_FUNCTION); |
| 200 | + if (ast_auth_header || ast_auth_key) |
| 201 | + throw Exception("Auth method is 'none', but auth header or auth key is set.", ErrorCodes::UNKNOWN_FUNCTION); |
168 | 202 | } |
| 203 | + else |
| 204 | + { |
| 205 | + throw Exception("Unknown auth method " + ast_auth_method.value(), ErrorCodes::UNKNOWN_FUNCTION); |
| 206 | + } |
| 207 | + } |
| 208 | + else |
| 209 | + { |
| 210 | + if (ast_auth_header || ast_auth_key) |
| 211 | + throw Exception("Auth method is 'none', but auth header or auth key is set.", ErrorCodes::UNKNOWN_FUNCTION); |
169 | 212 | } |
170 | | - function_core = std::move(url); |
| 213 | + function_core = std::move(kv_list); |
171 | 214 | } |
172 | 215 | /// proton: ends |
173 | 216 |
|
|
0 commit comments