Helper to create Enum data type from ASTEnumDataType values
| 54 | |
| 55 | /// Helper to create Enum data type from ASTEnumDataType values |
| 56 | static 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 |
| 80 | static DataTypePtr createTupleFromAST(const ASTTupleDataType * tuple_ast) |