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

Method parseArguments

src/TableFunctions/TableFunctionRedis.cpp:76–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void TableFunctionRedis::parseArguments(const ASTPtr & ast_function, ContextPtr context)
77{
78 const auto & func_args = ast_function->as<ASTFunction &>();
79 if (!func_args.arguments)
80 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function 'redis' must have arguments.");
81
82 ASTs & args = func_args.arguments->children;
83
84 if (args.size() < 3)
85 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Bad arguments count when creating Redis table function");
86
87 for (auto & arg : args)
88 arg = evaluateConstantExpressionOrIdentifierAsLiteral(arg, context);
89
90 auto parsed_host_port = parseAddress(checkAndGetLiteralArgument<String>(args[0], "host:port"), 6379);
91 configuration.host = parsed_host_port.first;
92 configuration.port = parsed_host_port.second;
93
94 primary_key = checkAndGetLiteralArgument<String>(args[1], "key");
95 structure = checkAndGetLiteralArgument<String>(args[2], "structure");
96
97 if (args.size() > 3)
98 configuration.db_index = static_cast<uint32_t>(checkAndGetLiteralArgument<UInt64>(args[3], "db_index"));
99 else
100 configuration.db_index = DEFAULT_REDIS_DB_INDEX;
101 if (args.size() > 4)
102 configuration.password = checkAndGetLiteralArgument<String>(args[4], "password");
103 else
104 configuration.password = DEFAULT_REDIS_PASSWORD;
105 if (args.size() > 5)
106 configuration.pool_size = static_cast<uint32_t>(checkAndGetLiteralArgument<UInt64>(args[5], "pool_size"));
107 else
108 configuration.pool_size = DEFAULT_REDIS_POOL_SIZE;
109
110 context->getRemoteHostFilter().checkHostAndPort(configuration.host, toString(configuration.port));
111
112 auto columns = parseColumnsListFromString(structure, context);
113 if (!columns.has(primary_key))
114 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Bad arguments redis table function structure should contains key.");
115}
116
117}
118

Callers

nothing calls this directly

Calls 8

parseAddressFunction · 0.85
checkHostAndPortMethod · 0.80
ExceptionClass · 0.50
toStringFunction · 0.50
sizeMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected