diff --git a/src/TableFunctions/TableFunctionNumbers.cpp b/src/TableFunctions/TableFunctionNumbers.cpp index 4658165735a..594075b1c82 100644 --- a/src/TableFunctions/TableFunctionNumbers.cpp +++ b/src/TableFunctions/TableFunctionNumbers.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include "registerTableFunctions.h" @@ -17,6 +18,7 @@ namespace DB namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; + extern const int ILLEGAL_TYPE_OF_ARGUMENT; } @@ -56,7 +58,16 @@ void registerTableFunctionNumbers(TableFunctionFactory & factory) template UInt64 TableFunctionNumbers::evaluateArgument(const Context & context, ASTPtr & argument) const { - return evaluateConstantExpressionOrIdentifierAsLiteral(argument, context)->as().value.safeGet(); + const auto & [field, type] = evaluateConstantExpression(argument, context); + + if (!isNativeNumber(type)) + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} expression, must be numeric type", type->getName()); + + Field converted = convertFieldToType(field, DataTypeUInt64()); + if (converted.isNull()) + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "The value {} is not representable as UInt64", applyVisitor(FieldVisitorToString(), field)); + + return converted.safeGet(); } } diff --git a/tests/queries/0_stateless/01702_system_numbers_scientific_notation.reference b/tests/queries/0_stateless/01702_system_numbers_scientific_notation.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01702_system_numbers_scientific_notation.sql b/tests/queries/0_stateless/01702_system_numbers_scientific_notation.sql new file mode 100644 index 00000000000..6e037ee4a2e --- /dev/null +++ b/tests/queries/0_stateless/01702_system_numbers_scientific_notation.sql @@ -0,0 +1,5 @@ +select * from numbers(1e2) format Null; +select * from numbers_mt(1e2) format Null; +select * from numbers_mt('100') format Null; -- { serverError 43 } +select * from numbers_mt(inf) format Null; -- { serverError 43 } +select * from numbers_mt(nan) format Null; -- { serverError 43 }