Helper to create Tuple data type from ASTTupleDataType
| 78 | |
| 79 | /// Helper to create Tuple data type from ASTTupleDataType |
| 80 | static 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 | |
| 109 | DataTypePtr DataTypeFactory::get(const String & full_name) const |
| 110 | { |
no test coverage detected