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

Function createTupleFromAST

src/DataTypes/DataTypeFactory.cpp:80–107  ·  view source on GitHub ↗

Helper to create Tuple data type from ASTTupleDataType

Source from the content-addressed store, hash-verified

78
79/// Helper to create Tuple data type from ASTTupleDataType
80static DataTypePtr createTupleFromAST(const ASTTupleDataType * tuple_ast)
81{
82 const auto arguments = tuple_ast->getArguments();
83 if (!arguments || arguments->children.empty())
84 return std::make_shared<DataTypeTuple>(DataTypes{});
85
86 DataTypes nested_types;
87 nested_types.reserve(arguments->children.size());
88
89 for (const auto & child : arguments->children)
90 nested_types.emplace_back(DataTypeFactory::instance().get(child));
91
92 /// If element_names is empty, it's an unnamed tuple
93 if (tuple_ast->element_names.empty())
94 return std::make_shared<DataTypeTuple>(nested_types);
95
96 /// Named tuple - validate all elements have names (no mixed named/unnamed)
97 for (const auto & elem_name : tuple_ast->element_names)
98 {
99 if (elem_name.empty())
100 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Names are specified not for all elements of Tuple type");
101 }
102
103 if (tuple_ast->element_names.size() != nested_types.size())
104 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Names are specified not for all elements of Tuple type");
105
106 return std::make_shared<DataTypeTuple>(nested_types, tuple_ast->element_names);
107}
108
109DataTypePtr DataTypeFactory::get(const String & full_name) const
110{

Callers 1

getImplMethod · 0.85

Calls 7

ExceptionClass · 0.50
getArgumentsMethod · 0.45
emptyMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected