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

Function registerStorageExecutable

src/Storages/StorageExecutable.cpp:224–744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223void registerStorageExecutable(StorageFactory & factory);
224void registerStorageExecutable(StorageFactory & factory)
225{
226 auto register_storage = [](const StorageFactory::Arguments & args, bool is_executable_pool) -> StoragePtr
227 {
228 auto local_context = args.getLocalContext();
229
230 if (args.engine_args.size() < 2)
231 throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
232 "StorageExecutable requires minimum 2 arguments: script_name, format, [input_query...]");
233
234 for (size_t i = 0; i < 2; ++i)
235 args.engine_args[i] = evaluateConstantExpressionOrIdentifierAsLiteral(args.engine_args[i], local_context);
236
237 auto script_name_with_arguments_value = checkAndGetLiteralArgument<String>(args.engine_args[0], "script_name_with_arguments_value");
238
239 VectorWithMemoryTracking<String> script_name_with_arguments;
240 boost::split(script_name_with_arguments, script_name_with_arguments_value, [](char c) { return c == ' '; });
241
242 auto script_name = script_name_with_arguments[0];
243 script_name_with_arguments.erase(script_name_with_arguments.begin());
244 auto format = checkAndGetLiteralArgument<String>(args.engine_args[1], "format");
245
246 VectorWithMemoryTracking<ASTPtr> input_queries;
247 for (size_t i = 2; i < args.engine_args.size(); ++i)
248 {
249 if (args.engine_args[i]->children.empty())
250 throw Exception(
251 ErrorCodes::BAD_ARGUMENTS, "StorageExecutable argument \"{}\" is invalid query",
252 args.engine_args[i]->formatForErrorMessage());
253
254 ASTPtr query = args.engine_args[i]->children.at(0);
255 if (!query->as<ASTSelectWithUnionQuery>())
256 throw Exception(
257 ErrorCodes::UNSUPPORTED_METHOD, "StorageExecutable argument \"{}\" is invalid input query",
258 query->formatForErrorMessage());
259
260 input_queries.emplace_back(std::move(query));
261 }
262
263 const auto & columns = args.columns;
264 const auto & constraints = args.constraints;
265
266 ExecutableSettings settings;
267 settings.script_name = script_name;
268 settings.script_arguments = script_name_with_arguments;
269 settings.is_executable_pool = is_executable_pool;
270
271 if (is_executable_pool)
272 {
273 size_t max_command_execution_time = 10;
274
275 size_t max_execution_time_seconds = static_cast<size_t>(args.getContext()->getSettingsRef()[Setting::max_execution_time].totalSeconds());
276 if (max_execution_time_seconds != 0 && max_command_execution_time > max_execution_time_seconds)
277 max_command_execution_time = max_execution_time_seconds;
278
279 settings[ExecutableSetting::max_command_execution_time] = max_command_execution_time;
280 }
281

Callers 1

registerStoragesFunction · 0.85

Calls 15

getLocalContextMethod · 0.80
registerStorageMethod · 0.80
ExceptionClass · 0.50
splitFunction · 0.50
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
formatForErrorMessageMethod · 0.45
atMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected