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

Function createEnumFromValues

src/DataTypes/DataTypeFactory.cpp:56–77  ·  view source on GitHub ↗

Helper to create Enum data type from ASTEnumDataType values

Source from the content-addressed store, hash-verified

54
55/// Helper to create Enum data type from ASTEnumDataType values
56static DataTypePtr createEnumFromValues(const String & type_name, const std::vector<std::pair<String, Int64>> & values)
57{
58 String type_name_upper = Poco::toUpper(type_name);
59 bool use_enum16 = (type_name_upper == "ENUM16");
60
61 if (!use_enum16 && type_name_upper == "ENUM")
62 {
63 /// Auto-detect Enum8 vs Enum16 based on values
64 for (const auto & [_, value] : values)
65 {
66 if (value < std::numeric_limits<Int8>::min() || value > std::numeric_limits<Int8>::max())
67 {
68 use_enum16 = true;
69 break;
70 }
71 }
72 }
73
74 if (use_enum16)
75 return std::make_shared<DataTypeEnum16>(checkAndBuildEnumValues<Int16>(values, "Enum16"));
76 return std::make_shared<DataTypeEnum8>(checkAndBuildEnumValues<Int8>(values, "Enum8"));
77}
78
79/// Helper to create Tuple data type from ASTTupleDataType
80static DataTypePtr createTupleFromAST(const ASTTupleDataType * tuple_ast)

Callers 1

getImplMethod · 0.85

Calls 3

toUpperFunction · 0.85
minFunction · 0.70
maxFunction · 0.70

Tested by

no test coverage detected