mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Fix problems
This commit is contained in:
parent
0b51e25a69
commit
927de75a47
@ -15,101 +15,25 @@ namespace ErrorCodes
|
||||
extern const int UNEXPECTED_AST_STRUCTURE;
|
||||
}
|
||||
|
||||
static DataTypePtr createForInt8(const ASTPtr & arguments)
|
||||
template <typename T>
|
||||
static DataTypePtr createNumericDataType(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments)
|
||||
{
|
||||
if (std::is_integral_v<T>)
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() > 1)
|
||||
throw Exception("INT8 data type family must not have more than one argument - display width", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
const auto * argument = arguments->children[0]->as<ASTLiteral>();
|
||||
if (!argument || argument->value.getType() != Field::Types::UInt64 || argument->value.get<UInt64>() == 0)
|
||||
throw Exception("INT8 data type family may have only a number (positive integer) as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
throw Exception(String(TypeName<T>::get()) + " data type family must not have more than one argument - display width", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeInt8>();
|
||||
}
|
||||
|
||||
static DataTypePtr createForInt16(const ASTPtr & arguments)
|
||||
else
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() > 1)
|
||||
throw Exception("INT16 data type family must not have more than one argument - display width", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
const auto * argument = arguments->children[0]->as<ASTLiteral>();
|
||||
if (!argument || argument->value.getType() != Field::Types::UInt64 || argument->value.get<UInt64>() == 0)
|
||||
throw Exception("INT16 data type family may have only a number (positive integer) as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeInt16>();
|
||||
}
|
||||
|
||||
static DataTypePtr createForInt32(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() > 1)
|
||||
throw Exception("INT32 data type family must not have more than one argument - display width", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
const auto * argument = arguments->children[0]->as<ASTLiteral>();
|
||||
if (!argument || argument->value.getType() != Field::Types::UInt64 || argument->value.get<UInt64>() == 0)
|
||||
throw Exception("INT32 data type family may have only a number (positive integer) as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeInt32>();
|
||||
}
|
||||
|
||||
static DataTypePtr createForInt64(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() > 1)
|
||||
throw Exception("INT64 data type family must not have more than one argument - display width", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
const auto * argument = arguments->children[0]->as<ASTLiteral>();
|
||||
if (!argument || argument->value.getType() != Field::Types::UInt64 || argument->value.get<UInt64>() == 0)
|
||||
throw Exception("INT64 data type family may have only a number (positive integer) as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeInt64>();
|
||||
}
|
||||
|
||||
static DataTypePtr createForFloat32(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() > 2)
|
||||
throw Exception("FLOAT32 data type family must not have more than two arguments - total number of digits and number of digits following the decimal point", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
else if (arguments->children.size() == 1) {
|
||||
const auto * argument = arguments->children[0]->as<ASTLiteral>();
|
||||
if (!argument || argument->value.getType() != Field::Types::UInt64)
|
||||
throw Exception("FLOAT32 data type family may have a non negative number as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
} else if (arguments->children.size() == 2) {
|
||||
const auto * beforePoint = arguments->children[0]->as<ASTLiteral>();
|
||||
const auto * afterPoint = arguments->children[1]->as<ASTLiteral>();
|
||||
if (!beforePoint || beforePoint->value.getType() != Field::Types::UInt64 ||
|
||||
!afterPoint|| afterPoint->value.getType() != Field::Types::UInt64)
|
||||
throw Exception("FLOAT32 data type family may have a non negative number as its arguments", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
throw Exception(String(TypeName<T>::get()) + " data type family must not have more than two arguments - total number of digits and number of digits following the decimal point", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeFloat32>();
|
||||
return std::make_shared<DataTypeNumber<T>>();
|
||||
}
|
||||
|
||||
static DataTypePtr createForFloat64(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments) {
|
||||
if (arguments->children.size() != 2)
|
||||
throw Exception("FLOAT64 data type family must have only two arguments - total number of digits and number of digits following the decimal point", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
else {
|
||||
const auto * beforePoint = arguments->children[0]->as<ASTLiteral>();
|
||||
const auto * afterPoint = arguments->children[1]->as<ASTLiteral>();
|
||||
if (!beforePoint || beforePoint->value.getType() != Field::Types::UInt64 ||
|
||||
!afterPoint|| afterPoint->value.getType() != Field::Types::UInt64)
|
||||
throw Exception("FLOAT64 data type family may have a non negative number as its arguments", ErrorCodes::UNEXPECTED_AST_STRUCTURE);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_shared<DataTypeFloat64>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void registerDataTypeNumbers(DataTypeFactory & factory)
|
||||
{
|
||||
@ -118,12 +42,12 @@ void registerDataTypeNumbers(DataTypeFactory & factory)
|
||||
factory.registerSimpleDataType("UInt32", [] { return DataTypePtr(std::make_shared<DataTypeUInt32>()); });
|
||||
factory.registerSimpleDataType("UInt64", [] { return DataTypePtr(std::make_shared<DataTypeUInt64>()); });
|
||||
|
||||
factory.registerDataType("Int8", createForInt8);
|
||||
factory.registerDataType("Int16", createForInt16);
|
||||
factory.registerDataType("Int32", createForInt32);
|
||||
factory.registerDataType("Int64", createForInt64);
|
||||
factory.registerDataType("Float32", createForFloat32);
|
||||
factory.registerDataType("Float64", createForFloat64);
|
||||
factory.registerDataType("Int8", createNumericDataType<Int8>);
|
||||
factory.registerDataType("Int16", createNumericDataType<Int16>);
|
||||
factory.registerDataType("Int32", createNumericDataType<Int32>);
|
||||
factory.registerDataType("Int64", createNumericDataType<Int64>);
|
||||
factory.registerDataType("Float32", createNumericDataType<Int32>);
|
||||
factory.registerDataType("Float64", createNumericDataType<Int64>);
|
||||
|
||||
/// These synonyms are added for compatibility.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user