2017-07-16 03:05:40 +00:00
# include <DataTypes/DataTypesNumber.h>
# include <DataTypes/DataTypeFactory.h>
2020-05-18 23:53:41 +00:00
# include <Parsers/IAST.h>
# include <Parsers/ASTLiteral.h>
2017-07-16 03:05:40 +00:00
namespace DB
{
2020-05-18 23:53:41 +00:00
namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH ;
extern const int UNEXPECTED_AST_STRUCTURE ;
}
2020-05-25 11:53:12 +00:00
template < typename T >
static DataTypePtr createNumericDataType ( const ASTPtr & arguments )
2020-05-18 23:53:41 +00:00
{
2020-05-25 11:53:12 +00:00
if ( arguments )
{
if ( std : : is_integral_v < T > )
{
if ( arguments - > children . size ( ) > 1 )
throw Exception ( String ( TypeName < T > : : get ( ) ) + " data type family must not have more than one argument - display width " , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2020-05-18 23:53:41 +00:00
}
2020-05-25 11:53:12 +00:00
else
{
if ( arguments - > children . size ( ) > 2 )
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 ) ;
2020-05-18 23:53:41 +00:00
}
}
2020-05-25 11:53:12 +00:00
return std : : make_shared < DataTypeNumber < T > > ( ) ;
2020-05-18 23:53:41 +00:00
}
2017-07-16 03:05:40 +00:00
void registerDataTypeNumbers ( DataTypeFactory & factory )
{
2020-03-10 18:16:14 +00:00
factory . registerSimpleDataType ( " UInt8 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeUInt8 > ( ) ) ; } ) ;
factory . registerSimpleDataType ( " UInt16 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeUInt16 > ( ) ) ; } ) ;
factory . registerSimpleDataType ( " UInt32 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeUInt32 > ( ) ) ; } ) ;
factory . registerSimpleDataType ( " UInt64 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeUInt64 > ( ) ) ; } ) ;
2020-05-25 11:53:12 +00:00
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 > ) ;
2017-07-16 05:09:47 +00:00
2019-01-22 19:56:53 +00:00
/// These synonyms are added for compatibility.
2017-07-16 05:09:47 +00:00
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " TINYINT " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
2020-05-12 13:29:20 +00:00
factory . registerAlias ( " BOOL " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " BOOLEAN " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INT1 " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " SMALLINT " , " Int16 " , DataTypeFactory : : CaseInsensitive ) ;
2020-05-12 13:29:20 +00:00
factory . registerAlias ( " INT2 " , " Int16 " , DataTypeFactory : : CaseInsensitive ) ;
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " INT " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
2020-05-12 13:29:20 +00:00
factory . registerAlias ( " INT4 " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " INTEGER " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " BIGINT " , " Int64 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " FLOAT " , " Float32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " DOUBLE " , " Float64 " , DataTypeFactory : : CaseInsensitive ) ;
2017-07-16 03:05:40 +00:00
}
}