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

Method parseArguments

src/TableFunctions/TableFunctionValues.cpp:115–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114template <bool interpret_first_argument_as_structure>
115void TableFunctionValues<interpret_first_argument_as_structure>::parseArguments(const ASTPtr & ast_function, ContextPtr context)
116{
117 ASTs & args_func = ast_function->children;
118
119 if (args_func.size() != 1)
120 throw Exception(ErrorCodes::LOGICAL_ERROR, "Table function '{}' must have arguments", getName());
121
122 ASTs & args = args_func.at(0)->children;
123
124 if (args.empty())
125 throw Exception(ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION, "Table function '{}' requires at least 1 argument", getName());
126
127 if constexpr (interpret_first_argument_as_structure)
128 {
129 const auto & literal = args[0]->as<const ASTLiteral>();
130 String value;
131 String error;
132 if (args.size() > 1 && literal && literal->value.tryGet(value) && tryParseColumnsListFromString(value, structure, context, error))
133 {
134 has_structure_in_arguments = true;
135 return;
136 }
137 }
138
139 has_structure_in_arguments = false;
140 DataTypes data_types = getTypesFromArgument(args[0], context);
141 for (size_t i = 1; i < args.size(); ++i)
142 {
143 auto arg_types = getTypesFromArgument(args[i], context);
144 if (data_types.size() != arg_types.size())
145 throw Exception(
146 ErrorCodes::CANNOT_EXTRACT_TABLE_STRUCTURE,
147 "Cannot determine a common structure for {} function arguments: the amount of columns is different for different arguments",
148 getName());
149 for (size_t j = 0; j != arg_types.size(); ++j)
150 data_types[j] = getLeastSupertype(DataTypes{data_types[j], arg_types[j]});
151 }
152
153 NamesAndTypesList names_and_types;
154 for (size_t i = 0; i != data_types.size(); ++i)
155 names_and_types.emplace_back("c" + std::to_string(i + 1), data_types[i]);
156 structure = ColumnsDescription(names_and_types);
157}
158
159template <bool interpret_first_argument_as_structure>
160ColumnsDescription TableFunctionValues<interpret_first_argument_as_structure>::getActualTableStructure(ContextPtr /*context*/, bool /*is_insert_query*/) const

Callers

nothing calls this directly

Calls 12

getTypesFromArgumentFunction · 0.85
getLeastSupertypeFunction · 0.85
ColumnsDescriptionClass · 0.70
ExceptionClass · 0.50
getNameFunction · 0.50
to_stringFunction · 0.50
sizeMethod · 0.45
atMethod · 0.45
emptyMethod · 0.45
tryGetMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected