mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 05:22:17 +00:00
68 lines
2.5 KiB
C++
68 lines
2.5 KiB
C++
|
#pragma once
|
||
|
#include <DataTypes/DataTypeDate.h>
|
||
|
#include <DataTypes/DataTypeDate32.h>
|
||
|
#include <DataTypes/DataTypeDateTime.h>
|
||
|
#include <DataTypes/DataTypeDateTime64.h>
|
||
|
#include <Functions/CustomWeekTransforms.h>
|
||
|
#include <Functions/IFunction.h>
|
||
|
#include <Functions/TransformDateTime64.h>
|
||
|
#include <IO/WriteHelpers.h>
|
||
|
#include <Interpreters/Context.h>
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
namespace ErrorCodes
|
||
|
{
|
||
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
||
|
}
|
||
|
|
||
|
template <typename Transform>
|
||
|
class IFunctionCustomWeek : public IFunction
|
||
|
{
|
||
|
public:
|
||
|
bool isVariadic() const override { return true; }
|
||
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
|
||
|
size_t getNumberOfArguments() const override { return 0; }
|
||
|
bool useDefaultImplementationForConstants() const override { return true; }
|
||
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; }
|
||
|
|
||
|
bool hasInformationAboutMonotonicity() const override { return true; }
|
||
|
|
||
|
Monotonicity getMonotonicityForRange(const IDataType & type, const Field & left, const Field & right) const override
|
||
|
{
|
||
|
if constexpr (std::is_same_v<typename Transform::FactorTransform, ZeroTransform>)
|
||
|
return {.is_monotonic = true, .is_always_monotonic = true};
|
||
|
|
||
|
const IFunction::Monotonicity is_monotonic = {.is_monotonic = true};
|
||
|
const IFunction::Monotonicity is_not_monotonic;
|
||
|
|
||
|
/// This method is called only if the function has one argument. Therefore, we do not care about the non-local time zone.
|
||
|
const DateLUTImpl & date_lut = DateLUT::instance();
|
||
|
|
||
|
if (left.isNull() || right.isNull())
|
||
|
return {};
|
||
|
|
||
|
/// The function is monotonous on the [left, right] segment, if the factor transformation returns the same values for them.
|
||
|
|
||
|
if (checkAndGetDataType<DataTypeDate>(&type))
|
||
|
{
|
||
|
return Transform::FactorTransform::execute(UInt16(left.get<UInt64>()), date_lut)
|
||
|
== Transform::FactorTransform::execute(UInt16(right.get<UInt64>()), date_lut)
|
||
|
? is_monotonic
|
||
|
: is_not_monotonic;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return Transform::FactorTransform::execute(UInt32(left.get<UInt64>()), date_lut)
|
||
|
== Transform::FactorTransform::execute(UInt32(right.get<UInt64>()), date_lut)
|
||
|
? is_monotonic
|
||
|
: is_not_monotonic;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
}
|