This commit is contained in:
nikitamikhaylov 2020-12-07 18:47:57 +03:00
parent 3c90065158
commit a8616ea262
10 changed files with 128 additions and 128 deletions

View File

@ -308,7 +308,7 @@ namespace DB
writeChar('0' + y / 1000, buf); y %= 1000;
writeChar('0' + y / 100, buf); y %= 100;
writeChar('0' + y / 10, buf); y %= 10;
writeChar('0' + y , buf);;
writeChar('0' + y , buf);
writeChar('-', buf);

View File

@ -16,7 +16,7 @@
namespace DB
{
template <typename Name, typename FromDataType, bool nullOnErrors>
class ExecutableFunctionFromMJD : public IExecutableFunctionImpl
class ExecutableFunctionFromModifiedJulianDay : public IExecutableFunctionImpl
{
public:
String getName() const override
@ -95,10 +95,10 @@ namespace DB
};
template <typename Name, typename FromDataType, bool nullOnErrors>
class FunctionBaseFromMJD : public IFunctionBaseImpl
class FunctionBaseFromModifiedJulianDay : public IFunctionBaseImpl
{
public:
explicit FunctionBaseFromMJD(DataTypes argument_types_, DataTypePtr return_type_)
explicit FunctionBaseFromModifiedJulianDay(DataTypes argument_types_, DataTypePtr return_type_)
: argument_types(std::move(argument_types_))
, return_type(std::move(return_type_)) {}
@ -119,7 +119,7 @@ namespace DB
ExecutableFunctionImplPtr prepare(const ColumnsWithTypeAndName &) const override
{
return std::make_unique<ExecutableFunctionFromMJD<Name, FromDataType, nullOnErrors>>();
return std::make_unique<ExecutableFunctionFromModifiedJulianDay<Name, FromDataType, nullOnErrors>>();
}
bool isInjective(const ColumnsWithTypeAndName &) const override
@ -146,14 +146,14 @@ namespace DB
};
template <typename Name, bool nullOnErrors>
class FromMJDOverloadResolver : public IFunctionOverloadResolverImpl
class FromModifiedJulianDayOverloadResolver : public IFunctionOverloadResolverImpl
{
public:
static constexpr auto name = Name::name;
static FunctionOverloadResolverImplPtr create(const Context &)
{
return std::make_unique<FromMJDOverloadResolver<Name, nullOnErrors>>();
return std::make_unique<FromModifiedJulianDayOverloadResolver<Name, nullOnErrors>>();
}
String getName() const override
@ -172,7 +172,7 @@ namespace DB
using FromIntType = typename Types::RightType;
using FromDataType = DataTypeNumber<FromIntType>;
base = std::make_unique<FunctionBaseFromMJD<Name, FromDataType, nullOnErrors>>(argument_types, return_type);
base = std::make_unique<FunctionBaseFromModifiedJulianDay<Name, FromDataType, nullOnErrors>>(argument_types, return_type);
return true;
};
bool built = callOnBasicType<void, true, false, false, false>(from_type->getTypeId(), call);
@ -190,7 +190,7 @@ namespace DB
*/
if (WhichDataType(from_type).isNullable()) // Nullable(Nothing)
{
return std::make_unique<FunctionBaseFromMJD<Name, DataTypeInt32, nullOnErrors>>(argument_types, return_type);
return std::make_unique<FunctionBaseFromModifiedJulianDay<Name, DataTypeInt32, nullOnErrors>>(argument_types, return_type);
}
else {
// Should not happen.
@ -230,19 +230,19 @@ namespace DB
}
};
struct NameFromMJD
struct NameFromModifiedJulianDay
{
static constexpr auto name = "fromMJD";
static constexpr auto name = "fromModifiedJulianDay";
};
struct NameFromMJDOrNull
struct NameFromModifiedJulianDayOrNull
{
static constexpr auto name = "fromMJDOrNull";
static constexpr auto name = "fromModifiedJulianDayOrNull";
};
void registerFunctionFromMJD(FunctionFactory & factory)
void registerFunctionFromModifiedJulianDay(FunctionFactory & factory)
{
factory.registerFunction<FromMJDOverloadResolver<NameFromMJD, false>>();
factory.registerFunction<FromMJDOverloadResolver<NameFromMJDOrNull, true>>();
factory.registerFunction<FromModifiedJulianDayOverloadResolver<NameFromModifiedJulianDay, false>>();
factory.registerFunction<FromModifiedJulianDayOverloadResolver<NameFromModifiedJulianDayOrNull, true>>();
}
}

View File

@ -18,7 +18,7 @@ void registerFunctionToMonday(FunctionFactory &);
void registerFunctionToISOWeek(FunctionFactory &);
void registerFunctionToISOYear(FunctionFactory &);
void registerFunctionToCustomWeek(FunctionFactory &);
void registerFunctionToMJD(FunctionFactory &);
void registerFunctionToModifiedJulianDay(FunctionFactory &);
void registerFunctionToStartOfMonth(FunctionFactory &);
void registerFunctionToStartOfQuarter(FunctionFactory &);
void registerFunctionToStartOfYear(FunctionFactory &);
@ -66,7 +66,7 @@ void registerFunctionSubtractYears(FunctionFactory &);
void registerFunctionDateDiff(FunctionFactory &);
void registerFunctionToTimeZone(FunctionFactory &);
void registerFunctionFormatDateTime(FunctionFactory &);
void registerFunctionFromMJD(FunctionFactory &);
void registerFunctionFromModifiedJulianDay(FunctionFactory &);
void registerFunctionDateTrunc(FunctionFactory &);
void registerFunctionsDateTime(FunctionFactory & factory)
@ -85,7 +85,7 @@ void registerFunctionsDateTime(FunctionFactory & factory)
registerFunctionToISOWeek(factory);
registerFunctionToISOYear(factory);
registerFunctionToCustomWeek(factory);
registerFunctionToMJD(factory);
registerFunctionToModifiedJulianDay(factory);
registerFunctionToStartOfMonth(factory);
registerFunctionToStartOfQuarter(factory);
registerFunctionToStartOfYear(factory);
@ -134,7 +134,7 @@ void registerFunctionsDateTime(FunctionFactory & factory)
registerFunctionDateDiff(factory);
registerFunctionToTimeZone(factory);
registerFunctionFormatDateTime(factory);
registerFunctionFromMJD(factory);
registerFunctionFromModifiedJulianDay(factory);
registerFunctionDateTrunc(factory);
}

View File

@ -20,7 +20,7 @@ namespace DB
}
template <typename Name, typename ToDataType, bool nullOnErrors>
class ExecutableFunctionToMJD : public IExecutableFunctionImpl
class ExecutableFunctionToModifiedJulianDay : public IExecutableFunctionImpl
{
public:
String getName() const override
@ -70,37 +70,37 @@ namespace DB
size_t current_offset = 0;
for (size_t i = 0; i < input_rows_count; ++i)
{
const size_t next_offset = offsets ? (*offsets)[i] : current_offset + fixed_string_size;
const size_t string_size = offsets ? next_offset - current_offset - 1 : fixed_string_size;
ReadBufferFromMemory read_buffer(&(*chars)[current_offset], string_size);
current_offset = next_offset;
const size_t next_offset = offsets ? (*offsets)[i] : current_offset + fixed_string_size;
const size_t string_size = offsets ? next_offset - current_offset - 1 : fixed_string_size;
ReadBufferFromMemory read_buffer(&(*chars)[current_offset], string_size);
current_offset = next_offset;
if constexpr (nullOnErrors)
{
try
{
const GregorianDate<> date(read_buffer);
vec_to[i] = date.toMJD<typename ToDataType::FieldType>();
(*vec_null_map_to)[i] = false;
}
catch (const Exception & e)
{
if (e.code() == ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED ||
e.code() == ErrorCodes::CANNOT_PARSE_DATE)
{
(*vec_null_map_to)[i] = true;
}
else
{
throw;
}
}
}
else
{
const GregorianDate<> date(read_buffer);
vec_to[i] = date.toMJD<typename ToDataType::FieldType>();
}
if constexpr (nullOnErrors)
{
try
{
const GregorianDate<> date(read_buffer);
vec_to[i] = date.toMJD<typename ToDataType::FieldType>();
(*vec_null_map_to)[i] = false;
}
catch (const Exception & e)
{
if (e.code() == ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED ||
e.code() == ErrorCodes::CANNOT_PARSE_DATE)
{
(*vec_null_map_to)[i] = true;
}
else
{
throw;
}
}
}
else
{
const GregorianDate<> date(read_buffer);
vec_to[i] = date.toMJD<typename ToDataType::FieldType>();
}
}
if constexpr (nullOnErrors)
@ -120,10 +120,10 @@ namespace DB
};
template <typename Name, typename ToDataType, bool nullOnErrors>
class FunctionBaseToMJD : public IFunctionBaseImpl
class FunctionBaseToModifiedJulianDay : public IFunctionBaseImpl
{
public:
explicit FunctionBaseToMJD(DataTypes argument_types_, DataTypePtr return_type_)
explicit FunctionBaseToModifiedJulianDay(DataTypes argument_types_, DataTypePtr return_type_)
: argument_types(std::move(argument_types_))
, return_type(std::move(return_type_)) {}
@ -144,7 +144,7 @@ namespace DB
ExecutableFunctionImplPtr prepare(const ColumnsWithTypeAndName &) const override
{
return std::make_unique<ExecutableFunctionToMJD<Name, ToDataType, nullOnErrors>>();
return std::make_unique<ExecutableFunctionToModifiedJulianDay<Name, ToDataType, nullOnErrors>>();
}
bool isInjective(const ColumnsWithTypeAndName &) const override
@ -171,14 +171,14 @@ namespace DB
};
template <typename Name, typename ToDataType, bool nullOnErrors>
class ToMJDOverloadResolver : public IFunctionOverloadResolverImpl
class ToModifiedJulianDayOverloadResolver : public IFunctionOverloadResolverImpl
{
public:
static constexpr auto name = Name::name;
static FunctionOverloadResolverImplPtr create(const Context &)
{
return std::make_unique<ToMJDOverloadResolver<Name, ToDataType, nullOnErrors>>();
return std::make_unique<ToModifiedJulianDayOverloadResolver<Name, ToDataType, nullOnErrors>>();
}
String getName() const override
@ -190,7 +190,7 @@ namespace DB
{
DataTypes argument_types = { arguments[0].type };
return std::make_unique<FunctionBaseToMJD<Name, ToDataType, nullOnErrors>>(argument_types, return_type);
return std::make_unique<FunctionBaseToModifiedJulianDay<Name, ToDataType, nullOnErrors>>(argument_types, return_type);
}
DataTypePtr getReturnType(const DataTypes & arguments) const override
@ -223,19 +223,19 @@ namespace DB
}
};
struct NameToMJD
struct NameToModifiedJulianDay
{
static constexpr auto name = "toMJD";
static constexpr auto name = "toModifiedJulianDay";
};
struct NameToMJDOrNull
struct NameToModifiedJulianDayOrNull
{
static constexpr auto name = "toMJDOrNull";
static constexpr auto name = "toModifiedJulianDayOrNull";
};
void registerFunctionToMJD(FunctionFactory & factory)
void registerFunctionToModifiedJulianDay(FunctionFactory & factory)
{
factory.registerFunction<ToMJDOverloadResolver<NameToMJD, DataTypeInt32, false>>();
factory.registerFunction<ToMJDOverloadResolver<NameToMJDOrNull, DataTypeInt32, true>>();
factory.registerFunction<ToModifiedJulianDayOverloadResolver<NameToModifiedJulianDay, DataTypeInt32, false>>();
factory.registerFunction<ToModifiedJulianDayOverloadResolver<NameToModifiedJulianDayOrNull, DataTypeInt32, true>>();
}
}

View File

@ -1,38 +0,0 @@
--
SELECT 'Invocation with constant';
SELECT toMJD('1858-11-16');
SELECT toMJD('1858-11-17');
SELECT toMJD('2020-11-01');
SELECT toMJD(NULL);
SELECT toMJD('unparsable'); -- { serverError 27 }
SELECT toMJD('1999-02-29'); -- { serverError 38 }
SELECT toMJD('1999-13-32'); -- { serverError 38 }
SELECT 'or null';
SELECT toMJDOrNull('2020-11-01');
SELECT toMJDOrNull('unparsable');
SELECT toMJDOrNull('1999-02-29');
SELECT toMJDOrNull('1999-13-32');
--
SELECT 'Invocation with String column';
DROP TABLE IF EXISTS toMJD_test;
CREATE TABLE toMJD_test (d String) ENGINE = Memory;
INSERT INTO toMJD_test VALUES ('1858-11-16'), ('1858-11-17'), ('2020-11-01');
SELECT toMJD(d) FROM toMJD_test;
DROP TABLE toMJD_test;
--
SELECT 'Invocation with FixedString column';
DROP TABLE IF EXISTS toMJD_test;
CREATE TABLE toMJD_test (d FixedString(10)) ENGINE = Memory;
INSERT INTO toMJD_test VALUES ('1858-11-16'), ('1858-11-17'), ('2020-11-01');
SELECT toMJD(d) FROM toMJD_test;
DROP TABLE toMJD_test;

View File

@ -0,0 +1,38 @@
--
SELECT 'Invocation with constant';
SELECT toModifiedJulianDay('1858-11-16');
SELECT toModifiedJulianDay('1858-11-17');
SELECT toModifiedJulianDay('2020-11-01');
SELECT toModifiedJulianDay(NULL);
SELECT toModifiedJulianDay('unparsable'); -- { serverError 27 }
SELECT toModifiedJulianDay('1999-02-29'); -- { serverError 38 }
SELECT toModifiedJulianDay('1999-13-32'); -- { serverError 38 }
SELECT 'or null';
SELECT toModifiedJulianDayOrNull('2020-11-01');
SELECT toModifiedJulianDayOrNull('unparsable');
SELECT toModifiedJulianDayOrNull('1999-02-29');
SELECT toModifiedJulianDayOrNull('1999-13-32');
--
SELECT 'Invocation with String column';
DROP TABLE IF EXISTS toModifiedJulianDay_test;
CREATE TABLE toModifiedJulianDay_test (d String) ENGINE = Memory;
INSERT INTO toModifiedJulianDay_test VALUES ('1858-11-16'), ('1858-11-17'), ('2020-11-01');
SELECT toModifiedJulianDay(d) FROM toModifiedJulianDay_test;
DROP TABLE toModifiedJulianDay_test;
--
SELECT 'Invocation with FixedString column';
DROP TABLE IF EXISTS toModifiedJulianDay_test;
CREATE TABLE toModifiedJulianDay_test (d FixedString(10)) ENGINE = Memory;
INSERT INTO toModifiedJulianDay_test VALUES ('1858-11-16'), ('1858-11-17'), ('2020-11-01');
SELECT toModifiedJulianDay(d) FROM toModifiedJulianDay_test;
DROP TABLE toModifiedJulianDay_test;

View File

@ -1,26 +0,0 @@
--
SELECT 'Invocation with constant';
SELECT fromMJD(-1);
SELECT fromMJD(0);
SELECT fromMJD(59154);
SELECT fromMJD(NULL);
SELECT fromMJD(-678942); -- { serverError 490 }
SELECT fromMJD(2973484); -- { serverError 490 }
SELECT 'or null';
SELECT fromMJDOrNull(59154);
SELECT fromMJDOrNull(NULL);
SELECT fromMJDOrNull(-678942);
SELECT fromMJDOrNull(2973484);
--
SELECT 'Invocation with Int32 column';
DROP TABLE IF EXISTS fromMJD_test;
CREATE TABLE fromMJD_test (d Int32) ENGINE = Memory;
INSERT INTO fromMJD_test VALUES (-1), (0), (59154);
SELECT fromMJD(d) FROM fromMJD_test;
DROP TABLE fromMJD_test;

View File

@ -0,0 +1,26 @@
--
SELECT 'Invocation with constant';
SELECT fromModifiedJulianDay(-1);
SELECT fromModifiedJulianDay(0);
SELECT fromModifiedJulianDay(59154);
SELECT fromModifiedJulianDay(NULL);
SELECT fromModifiedJulianDay(-678942); -- { serverError 490 }
SELECT fromModifiedJulianDay(2973484); -- { serverError 490 }
SELECT 'or null';
SELECT fromModifiedJulianDayOrNull(59154);
SELECT fromModifiedJulianDayOrNull(NULL);
SELECT fromModifiedJulianDayOrNull(-678942);
SELECT fromModifiedJulianDayOrNull(2973484);
--
SELECT 'Invocation with Int32 column';
DROP TABLE IF EXISTS fromModifiedJulianDay_test;
CREATE TABLE fromModifiedJulianDay_test (d Int32) ENGINE = Memory;
INSERT INTO fromModifiedJulianDay_test VALUES (-1), (0), (59154);
SELECT fromModifiedJulianDay(d) FROM fromModifiedJulianDay_test;
DROP TABLE fromModifiedJulianDay_test;