Fix strange code

This commit is contained in:
Alexey Milovidov 2020-06-23 01:06:25 +03:00
parent 1191679965
commit 112f6153a7
3 changed files with 28 additions and 13 deletions

View File

@ -20,19 +20,34 @@
#include <optional>
#include <string>
namespace DB
{
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
}
static constexpr UInt32 max_scale = 9;
DataTypeDateTime64::DataTypeDateTime64(UInt32 scale_, const std::string & time_zone_name)
: DataTypeDecimalBase<DateTime64>(DecimalUtils::maxPrecision<DateTime64>(), scale_),
TimezoneMixin(time_zone_name)
{
if (scale > max_scale)
throw Exception("Scale " + std::to_string(scale) + " is too large for DateTime64. Maximum is up to nanoseconds (9).",
ErrorCodes::ARGUMENT_OUT_OF_BOUND);
}
DataTypeDateTime64::DataTypeDateTime64(UInt32 scale_, const TimezoneMixin & time_zone_info)
: DataTypeDecimalBase<DateTime64>(DecimalUtils::maxPrecision<DateTime64>() - scale_, scale_),
: DataTypeDecimalBase<DateTime64>(DecimalUtils::maxPrecision<DateTime64>(), scale_),
TimezoneMixin(time_zone_info)
{}
{
if (scale > max_scale)
throw Exception("Scale " + std::to_string(scale) + " is too large for DateTime64. Maximum is up to nanoseconds (9).",
ErrorCodes::ARGUMENT_OUT_OF_BOUND);
}
std::string DataTypeDateTime64::doGetName() const
{

View File

@ -72,7 +72,7 @@ public:
{
if (unlikely(precision < 1 || precision > maxPrecision()))
throw Exception("Precision " + std::to_string(precision) + " is out of bounds", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
if (unlikely(scale < 0 || static_cast<UInt32>(scale) > maxPrecision()))
if (unlikely(scale > maxPrecision()))
throw Exception("Scale " + std::to_string(scale) + " is out of bounds", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
}

View File

@ -49,7 +49,7 @@ SELECT toDateTime64('2011-11-11 11:11:11.-11111111111111111111', 0); -- { server
SELECT toDateTime64('2011-11-11 11:11:11.-111111111111111111111', 0); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.+1', 0); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.++11', 10); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.++11', 10); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+111', 3); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.+++1111', 5); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.+11111', 7); -- { serverError 6 }
@ -59,13 +59,13 @@ SELECT toDateTime64('2011-11-11 11:11:11.++++++11111111', 8); -- { serverError 6
SELECT toDateTime64('2011-11-11 11:11:11.+111111111', 9); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.+++++++1111111111', 6); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.+11111111111', 4); -- { serverError 6 }
SELECT toDateTime64('2011-11-11 11:11:11.++++++++111111111111', 11); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+1111111111111', 15); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+++++++++11111111111111', 13); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+111111111111111', 12); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.++++++++++1111111111111111', 16); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+11111111111111111', 14); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+++++++++++111111111111111111', 15); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+1111111111111111111', 17); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.++++++++111111111111', 11); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+1111111111111', 15); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+++++++++11111111111111', 13); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+111111111111111', 12); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.++++++++++1111111111111111', 16); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+11111111111111111', 14); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+++++++++++111111111111111111', 15); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+1111111111111111111', 17); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.++++++++++++11111111111111111111', 19); -- { serverError 69 }
SELECT toDateTime64('2011-11-11 11:11:11.+111111111111111111111', 18); -- { serverError 407 }
SELECT toDateTime64('2011-11-11 11:11:11.+111111111111111111111', 18); -- { serverError 69 }