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

Method parseArguments

src/TableFunctions/TableFunctionRemote.cpp:42–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42void TableFunctionRemote::parseArguments(const ASTPtr & ast_function, ContextPtr context)
43{
44 ASTs & args_func = ast_function->children;
45
46 String cluster_name;
47 String cluster_description;
48 String database = "system";
49 String table = "one"; /// The table containing one row is used by default for queries without explicit table specification.
50 String username = "default";
51 String password;
52
53 if (args_func.size() != 1)
54 throw Exception(help_message, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
55
56 ASTs & args = args_func.at(0)->children;
57
58 /**
59 * Number of arguments for remote function is 6.
60 * Number of arguments for cluster function is 4.
61 * For now named collection can be used only for remote as cluster does not require credentials.
62 */
63 size_t max_args = is_cluster_function ? 4 : 6;
64 NamedCollectionPtr named_collection;
65 VectorWithMemoryTracking<std::pair<std::string, ASTPtr>> complex_args;
66 if (!is_cluster_function && (named_collection = tryGetNamedCollectionWithOverrides(args, context, false, &complex_args)))
67 {
68 validateNamedCollection<ValidateKeysMultiset<ExternalDatabaseEqualKeysSet>>(
69 *named_collection,
70 {"addresses_expr", "host", "hostname", "table"},
71 {"username", "user", "password", "sharding_key", "port", "database", "db"});
72
73 if (!complex_args.empty())
74 {
75 for (const auto & [arg_name, arg_ast] : complex_args)
76 {
77 if (arg_name == "database" || arg_name == "db")
78 {
79 /// A table function is allowed here (remote(nc, database = mysql(...))), mirroring the
80 /// positional signature remote('addr', table_function()). Any other expression is a
81 /// database name, so a non-function node never reaches TableFunctionFactory::get().
82 const auto * function = arg_ast->as<ASTFunction>();
83 if (function && TableFunctionFactory::instance().isTableFunctionName(function->name))
84 remote_table_function_ptr = arg_ast;
85 else
86 database = checkAndGetLiteralArgument<String>(
87 evaluateConstantExpressionForDatabaseName(arg_ast, context), "database");
88 }
89 else if (arg_name == "sharding_key")
90 sharding_key = arg_ast;
91 else
92 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected argument representation for {}", arg_name);
93 }
94 }
95 else
96 database = named_collection->getAnyOrDefault<String>({"db", "database"}, "default");
97
98 cluster_description = named_collection->getOrDefault<String>("addresses_expr", "");
99 if (cluster_description.empty() && named_collection->hasAny({"host", "hostname"}))

Callers

nothing calls this directly

Calls 15

parseRemoteDescriptionFunction · 0.85
isTableFunctionNameMethod · 0.80
get<UInt64>Method · 0.80
getTCPPortSecureMethod · 0.80
checkHostAndPortMethod · 0.80
getTCPPortMethod · 0.80
getApplicationTypeMethod · 0.80
ExceptionClass · 0.50

Tested by

no test coverage detected