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

Function create

src/DataTypes/DataTypeEnum.cpp:362–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360}
361
362static 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
392template <typename TypeBase>

Callers 2

doGetSerializationMethod · 0.70
registerDataTypeEnumFunction · 0.70

Calls 7

autoAssignNumberForEnumFunction · 0.85
checkASTStructureFunction · 0.85
maxFunction · 0.70
minFunction · 0.70
ExceptionClass · 0.50
emptyMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected