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>
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 ;
}
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-07-21 08:16:15 +00:00
factory . registerDataType ( " UInt8 " , createNumericDataType < UInt8 > ) ;
factory . registerDataType ( " UInt16 " , createNumericDataType < UInt16 > ) ;
factory . registerDataType ( " UInt32 " , createNumericDataType < UInt32 > ) ;
factory . registerDataType ( " UInt64 " , createNumericDataType < UInt64 > ) ;
2020-03-10 18:16:14 +00:00
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 > ) ;
2020-05-25 17:10:44 +00:00
factory . registerDataType ( " Float32 " , createNumericDataType < Float32 > ) ;
factory . registerDataType ( " Float64 " , createNumericDataType < Float64 > ) ;
2017-07-16 05:09:47 +00:00
2020-08-19 11:52:17 +00:00
factory . registerSimpleDataType ( " UInt256 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeUInt256 > ( ) ) ; } ) ;
factory . registerSimpleDataType ( " Int128 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeInt128 > ( ) ) ; } ) ;
factory . registerSimpleDataType ( " Int256 " , [ ] { return DataTypePtr ( std : : make_shared < DataTypeInt256 > ( ) ) ; } ) ;
/// 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 ) ;
2020-05-17 08:35:08 +00:00
factory . registerAlias ( " INT1 " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ; /// MySQL
factory . registerAlias ( " BYTE " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ; /// MS Access
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " SMALLINT " , " Int16 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INT " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INTEGER " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " BIGINT " , " Int64 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " FLOAT " , " Float32 " , DataTypeFactory : : CaseInsensitive ) ;
2020-05-17 08:22:59 +00:00
factory . registerAlias ( " REAL " , " Float32 " , DataTypeFactory : : CaseInsensitive ) ;
2020-05-17 08:35:08 +00:00
factory . registerAlias ( " SINGLE " , " Float32 " , DataTypeFactory : : CaseInsensitive ) ; /// MS Access
2018-07-23 16:10:57 +00:00
factory . registerAlias ( " DOUBLE " , " Float64 " , DataTypeFactory : : CaseInsensitive ) ;
2020-07-20 17:44:38 +00:00
factory . registerAlias ( " MEDIUMINT " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ; /// MySQL
2020-06-18 12:52:05 +00:00
2020-06-07 20:02:57 +00:00
factory . registerAlias ( " DOUBLE PRECISION " , " Float64 " , DataTypeFactory : : CaseInsensitive ) ;
2020-06-22 11:45:45 +00:00
/// MySQL
factory . registerAlias ( " TINYINT SIGNED " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INT1 SIGNED " , " Int8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " SMALLINT SIGNED " , " Int16 " , DataTypeFactory : : CaseInsensitive ) ;
2020-07-20 17:44:38 +00:00
factory . registerAlias ( " MEDIUMINT SIGNED " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
2020-06-22 11:45:45 +00:00
factory . registerAlias ( " INT SIGNED " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INTEGER SIGNED " , " Int32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " BIGINT SIGNED " , " Int64 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " TINYINT UNSIGNED " , " UInt8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INT1 UNSIGNED " , " UInt8 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " SMALLINT UNSIGNED " , " UInt16 " , DataTypeFactory : : CaseInsensitive ) ;
2020-07-20 17:44:38 +00:00
factory . registerAlias ( " MEDIUMINT UNSIGNED " , " UInt32 " , DataTypeFactory : : CaseInsensitive ) ;
2020-06-22 11:45:45 +00:00
factory . registerAlias ( " INT UNSIGNED " , " UInt32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " INTEGER UNSIGNED " , " UInt32 " , DataTypeFactory : : CaseInsensitive ) ;
factory . registerAlias ( " BIGINT UNSIGNED " , " UInt64 " , DataTypeFactory : : CaseInsensitive ) ;
2017-07-16 03:05:40 +00:00
}
}