| 360 | } |
| 361 | |
| 362 | static DataTypePtr create(const ASTPtr & arguments, bool is_add = false) |
| 363 | { |
| 364 | if (!arguments || arguments->children.empty()) |
| 365 | throw Exception(ErrorCodes::EMPTY_DATA_PASSED, "Enum data type cannot be empty"); |
| 366 | |
| 367 | std::vector<UInt8> relative_flags = autoAssignNumberForEnum(arguments, is_add); |
| 368 | /// Children must be functions 'equals' with string literal as left argument and numeric literal as right argument. |
| 369 | for (const ASTPtr & child : arguments->children) |
| 370 | { |
| 371 | checkASTStructure(child); |
| 372 | |
| 373 | const auto * func = child->as<ASTFunction>(); |
| 374 | const auto * value_literal = func->arguments->children[1]->as<ASTLiteral>(); |
| 375 | |
| 376 | if (!value_literal |
| 377 | || (value_literal->value.getType() != Field::Types::UInt64 && value_literal->value.getType() != Field::Types::Int64)) |
| 378 | throw Exception(ErrorCodes::UNEXPECTED_AST_STRUCTURE, |
| 379 | "Elements of Enum data type must be of form: " |
| 380 | "'name' = number or 'name', where name is string literal and number is an integer"); |
| 381 | |
| 382 | Int64 value = value_literal->value.safeGet<Int64>(); |
| 383 | |
| 384 | if (value > std::numeric_limits<Int8>::max() || value < std::numeric_limits<Int8>::min()) |
| 385 | return createExact<DataTypeEnum16>(arguments, is_add, false /*auto_assign*/, std::move(relative_flags)); |
| 386 | } |
| 387 | |
| 388 | return createExact<DataTypeEnum8>(arguments, is_add, false /*auto_assign*/, std::move(relative_flags)); |
| 389 | } |
| 390 | |
| 391 | // Used by ADD ENUM VALUES |
| 392 | template <typename TypeBase> |
no test coverage detected