FunctionsDateTime.h 42.4 KB
Newer Older
A
Alexey Milovidov 已提交
1 2
#pragma once

3 4 5 6 7
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeString.h>
8

9 10 11
#include <Columns/ColumnsNumber.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnArray.h>
12
#include <Columns/ColumnString.h>
13
#include <Columns/ColumnFixedString.h>
14

15 16
#include <Common/typeid_cast.h>

17
#include <IO/WriteHelpers.h>
18

19
#include <Functions/IFunction.h>
20
#include <Functions/FunctionHelpers.h>
A
Alexey Milovidov 已提交
21

22 23
#include <common/DateLUT.h>

24
#include <type_traits>
A
Alexey Milovidov 已提交
25

26

A
Alexey Milovidov 已提交
27 28 29
namespace DB
{

30 31 32 33 34
namespace ErrorCodes
{
    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}

F
f1yegor 已提交
35
/** Functions for working with date and time.
A
Alexey Milovidov 已提交
36 37
  *
  * toYear, toMonth, toDayOfMonth, toDayOfWeek, toHour, toMinute, toSecond,
38 39
  * toMonday, toStartOfMonth, toStartOfYear, toStartOfMinute, toStartOfFiveMinute
  * toStartOfHour, toTime,
40
  * now, today, yesterday
41
  * TODO: makeDate, makeDateTime
42
  *
F
f1yegor 已提交
43
  * (toDate - located in FunctionConversion.h file)
A
Alexey Milovidov 已提交
44
  *
F
f1yegor 已提交
45
  * Return types:
A
Alexey Milovidov 已提交
46 47
  *  toYear -> UInt16
  *  toMonth, toDayOfMonth, toDayOfWeek, toHour, toMinute, toSecond -> UInt8
48 49
  *  toMonday, toStartOfMonth, toStartOfYear -> Date
  *  toStartOfMinute, toStartOfHour, toTime, now -> DateTime
50
  *
F
f1yegor 已提交
51
  * And also:
52 53
  *
  * timeSlot(EventTime)
F
f1yegor 已提交
54
  * - rounds the time to half an hour.
55
  *
56
  * timeSlots(StartTime, Duration)
F
f1yegor 已提交
57 58 59 60
  * - for the time interval beginning at `StartTime` and continuing `Duration` seconds,
  *   returns an array of time points, consisting of rounding down to half an hour of points from this interval.
  *  For example, timeSlots(toDateTime('2012-01-01 12:20:00'), 600) = [toDateTime('2012-01-01 12:00:00'), toDateTime('2012-01-01 12:30:00')].
  *  This is necessary to search for hits that are part of the corresponding visit.
A
Alexey Milovidov 已提交
61 62
  */

63 64 65

#define TIME_SLOT_SIZE 1800

F
f1yegor 已提交
66 67
/** Extra transformations.
  * Represents two functions - from datetime (UInt32) and from date (UInt16).
68
  *
F
f1yegor 已提交
69 70 71
  * Also, the "factor transformation" F is defined for the T transformation.
  * This is a transformation of F such that its value identifies the region of monotonicity T
  *  (for a fixed value of F, the transformation T is monotonic).
72
  *
F
f1yegor 已提交
73
  * Or, figuratively, if T is similar to taking the remainder of division, then F is similar to division.
74
  *
F
f1yegor 已提交
75 76
  * Example: to convert T "get the day number in the month" (2015-02-03 -> 3),
  *  factor-transformation F is "round to the nearest month" (2015-02-03 -> 2015-02-01).
77
  */
78

F
f1yegor 已提交
79
/// This factor transformation will say that the function is monotone everywhere.
80
struct ZeroTransform
A
Alexey Milovidov 已提交
81
{
82 83
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone) { return 0; }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone) { return 0; }
A
Alexey Milovidov 已提交
84 85
};

86
struct ToDateImpl
A
Alexey Milovidov 已提交
87
{
88 89
    static constexpr auto name = "toDate";

90 91 92 93 94 95 96 97
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return UInt16(time_zone.toDayNum(t));
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return d;
    }
98

99
    using FactorTransform = ZeroTransform;
100 101 102 103
};

struct ToStartOfDayImpl
{
104 105
    static constexpr auto name = "toStartOfDay";

106 107 108 109 110 111 112 113
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toDate(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return d;
    }
114

115
    using FactorTransform = ZeroTransform;
A
Alexey Milovidov 已提交
116 117
};

118
struct ToMondayImpl
A
Alexey Milovidov 已提交
119
{
120 121
    static constexpr auto name = "toMonday";

122 123 124 125 126 127 128 129
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t));
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfWeek(DayNum_t(d));
    }
A
Alexey Milovidov 已提交
130

131
    using FactorTransform = ZeroTransform;
A
Alexey Milovidov 已提交
132 133 134 135
};

struct ToStartOfMonthImpl
{
136 137
    static constexpr auto name = "toStartOfMonth";

138 139 140 141 142 143 144 145
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfMonth(time_zone.toDayNum(t));
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfMonth(DayNum_t(d));
    }
146

147
    using FactorTransform = ZeroTransform;
A
Alexey Milovidov 已提交
148 149
};

150 151
struct ToStartOfQuarterImpl
{
152 153
    static constexpr auto name = "toStartOfQuarter";

154 155 156 157 158 159 160 161
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfQuarter(time_zone.toDayNum(t));
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfQuarter(DayNum_t(d));
    }
162

163
    using FactorTransform = ZeroTransform;
164 165
};

166 167
struct ToStartOfYearImpl
{
168 169
    static constexpr auto name = "toStartOfYear";

170 171 172 173 174 175 176 177
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfYear(time_zone.toDayNum(t));
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toFirstDayNumOfYear(DayNum_t(d));
    }
178

179
    using FactorTransform = ZeroTransform;
180 181 182
};


A
Alexey Milovidov 已提交
183 184
struct ToTimeImpl
{
185 186
    static constexpr auto name = "toTime";

F
f1yegor 已提交
187
    /// When transforming to time, the date will be equated to 1970-01-02.
188 189 190 191
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toTime(t) + 86400;
    }
192

193 194 195 196
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toTime", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
197

198
    using FactorTransform = ToDateImpl;
A
Alexey Milovidov 已提交
199 200
};

201 202
struct ToStartOfMinuteImpl
{
203 204
    static constexpr auto name = "toStartOfMinute";

205 206
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
207
        return time_zone.toStartOfMinute(t);
208 209 210 211 212
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toStartOfMinute", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
213

214
    using FactorTransform = ZeroTransform;
215 216
};

217 218
struct ToStartOfFiveMinuteImpl
{
219 220
    static constexpr auto name = "toStartOfFiveMinute";

221 222
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
223
        return time_zone.toStartOfFiveMinute(t);
224 225 226 227 228
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toStartOfFiveMinute", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
229

230
    using FactorTransform = ZeroTransform;
231 232
};

233 234
struct ToStartOfHourImpl
{
235 236
    static constexpr auto name = "toStartOfHour";

237 238
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
239
        return time_zone.toStartOfHour(t);
240
    }
241

242 243 244 245
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toStartOfHour", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
246

247
    using FactorTransform = ZeroTransform;
248 249 250 251
};

struct ToYearImpl
{
252 253
    static constexpr auto name = "toYear";

254 255 256 257 258 259 260 261
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toYear(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toYear(DayNum_t(d));
    }
262

263
    using FactorTransform = ZeroTransform;
264 265 266 267
};

struct ToMonthImpl
{
268 269
    static constexpr auto name = "toMonth";

270 271 272 273 274 275 276 277
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toMonth(t);
    }
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toMonth(DayNum_t(d));
    }
278

279
    using FactorTransform = ToStartOfYearImpl;
280 281 282 283
};

struct ToDayOfMonthImpl
{
284 285
    static constexpr auto name = "toDayOfMonth";

286 287 288 289 290 291 292 293
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toDayOfMonth(t);
    }
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toDayOfMonth(DayNum_t(d));
    }
294

295
    using FactorTransform = ToStartOfMonthImpl;
296 297 298 299
};

struct ToDayOfWeekImpl
{
300 301
    static constexpr auto name = "toDayOfWeek";

302 303 304 305 306 307 308 309
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toDayOfWeek(t);
    }
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toDayOfWeek(DayNum_t(d));
    }
310

311
    using FactorTransform = ToMondayImpl;
312 313 314 315
};

struct ToHourImpl
{
316 317
    static constexpr auto name = "toHour";

318 319 320 321
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toHour(t);
    }
322

323 324 325 326
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toHour", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
327

328
    using FactorTransform = ToDateImpl;
329 330 331 332
};

struct ToMinuteImpl
{
333 334
    static constexpr auto name = "toMinute";

335 336
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
337
        return time_zone.toMinute(t);
338 339 340 341 342
    }
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toMinute", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
343

344
    using FactorTransform = ToStartOfHourImpl;
345 346 347 348
};

struct ToSecondImpl
{
349 350
    static constexpr auto name = "toSecond";

351 352
    static inline UInt8 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
353
        return time_zone.toSecond(t);
354 355 356 357 358
    }
    static inline UInt8 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toSecond", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
359

360
    using FactorTransform = ToStartOfMinuteImpl;
361 362
};

363 364
struct ToRelativeYearNumImpl
{
365 366
    static constexpr auto name = "toRelativeYearNum";

367 368 369 370 371 372 373 374
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toYear(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toYear(DayNum_t(d));
    }
375

376
    using FactorTransform = ZeroTransform;
377 378 379 380
};

struct ToRelativeMonthNumImpl
{
381 382
    static constexpr auto name = "toRelativeMonthNum";

383 384 385 386 387 388 389 390
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeMonthNum(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeMonthNum(DayNum_t(d));
    }
391

392
    using FactorTransform = ZeroTransform;
393 394 395 396
};

struct ToRelativeWeekNumImpl
{
397 398
    static constexpr auto name = "toRelativeWeekNum";

399 400 401 402 403 404 405 406
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeWeekNum(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeWeekNum(DayNum_t(d));
    }
407

408
    using FactorTransform = ZeroTransform;
409 410 411 412
};

struct ToRelativeDayNumImpl
{
413 414
    static constexpr auto name = "toRelativeDayNum";

415 416 417 418 419 420 421 422
    static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toDayNum(t);
    }
    static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return static_cast<DayNum_t>(d);
    }
423

424
    using FactorTransform = ZeroTransform;
425 426 427 428 429
};


struct ToRelativeHourNumImpl
{
430 431
    static constexpr auto name = "toRelativeHourNum";

432 433 434 435 436 437 438 439
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeHourNum(t);
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toRelativeHourNum", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
440

441
    using FactorTransform = ZeroTransform;
442 443 444 445
};

struct ToRelativeMinuteNumImpl
{
446 447
    static constexpr auto name = "toRelativeMinuteNum";

448 449 450 451 452 453 454 455
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toRelativeMinuteNum(t);
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toRelativeMinuteNum", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
456

457
    using FactorTransform = ZeroTransform;
458 459 460 461
};

struct ToRelativeSecondNumImpl
{
462 463
    static constexpr auto name = "toRelativeSecondNum";

464 465 466 467 468 469 470 471
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return t;
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        throw Exception("Illegal type Date of argument for function toRelativeSecondNum", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
472

473
    using FactorTransform = ZeroTransform;
474 475
};

476 477
struct ToYYYYMMImpl
{
478 479
    static constexpr auto name = "toYYYYMM";

480 481 482 483 484 485 486 487 488 489 490 491 492 493
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMM(t);
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMM(static_cast<DayNum_t>(d));
    }

    using FactorTransform = ZeroTransform;
};

struct ToYYYYMMDDImpl
{
494 495
    static constexpr auto name = "toYYYYMMDD";

496 497 498 499 500 501 502 503 504 505 506 507 508 509
    static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMMDD(t);
    }
    static inline UInt32 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMMDD(static_cast<DayNum_t>(d));
    }

    using FactorTransform = ZeroTransform;
};

struct ToYYYYMMDDhhmmssImpl
{
510 511
    static constexpr auto name = "toYYYYMMDDhhmmss";

512 513 514 515 516 517 518 519 520 521 522 523
    static inline UInt64 execute(UInt32 t, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMMDDhhmmss(t);
    }
    static inline UInt64 execute(UInt16 d, const DateLUTImpl & time_zone)
    {
        return time_zone.toNumYYYYMMDDhhmmss(time_zone.toDate(static_cast<DayNum_t>(d)));
    }

    using FactorTransform = ZeroTransform;
};

524

A
Alexey Milovidov 已提交
525
template <typename FromType, typename ToType, typename Transform>
526
struct Transformer
527
{
528 529 530 531
    static void vector(const PaddedPODArray<FromType> & vec_from, PaddedPODArray<ToType> & vec_to, const DateLUTImpl & time_zone)
    {
        size_t size = vec_from.size();
        vec_to.resize(size);
532

533 534 535
        for (size_t i = 0; i < size; ++i)
            vec_to[i] = Transform::execute(vec_from[i], time_zone);
    }
536
};
537

538

539
template <typename FromType, typename ToType, typename Transform>
540 541
struct DateTimeTransformImpl
{
542 543 544 545
    static void execute(Block & block, const ColumnNumbers & arguments, size_t result)
    {
        using Op = Transformer<FromType, ToType, Transform>;

546
        const ColumnConst * time_zone_column = nullptr;
547 548 549

        if (arguments.size() == 2)
        {
550
            time_zone_column = checkAndGetColumnConst<ColumnString>(block.getByPosition(arguments[1]).column.get());
551 552

            if (!time_zone_column)
553
                throw Exception("Illegal column " + block.getByPosition(arguments[1]).column->getName()
554
                    + " of second (time zone) argument of function " + Transform::name + ", must be constant string",
555 556 557 558
                    ErrorCodes::ILLEGAL_COLUMN);
        }

        const DateLUTImpl & time_zone = time_zone_column
559
            ? DateLUT::instance(time_zone_column->getValue<String>())
560 561
            : DateLUT::instance();

562 563
        const ColumnPtr source_col = block.getByPosition(arguments[0]).column;
        if (const auto * sources = checkAndGetColumn<ColumnVector<FromType>>(source_col.get()))
564 565
        {
            auto col_to = std::make_shared<ColumnVector<ToType>>();
566
            block.getByPosition(result).column = col_to;
567 568 569 570
            Op::vector(sources->getData(), col_to->getData(), time_zone);
        }
        else
        {
571
            throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName()
572
                + " of first argument of function " + Transform::name,
573 574 575
                ErrorCodes::ILLEGAL_COLUMN);
        }
    }
A
Alexey Milovidov 已提交
576 577
};

578

579
template <typename ToDataType, typename Transform>
A
Alexey Milovidov 已提交
580 581 582
class FunctionDateOrDateTimeToSomething : public IFunction
{
public:
583
    static constexpr auto name = Transform::name;
584 585 586 587 588 589 590 591 592 593 594 595 596 597
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionDateOrDateTimeToSomething>(); };

    String getName() const override
    {
        return name;
    }

    bool isVariadic() const override { return true; }
    size_t getNumberOfArguments() const override { return 0; }

    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
        if (arguments.size() == 1)
        {
598 599
            if (!checkDataType<DataTypeDate>(arguments[0].get())
                && !checkDataType<DataTypeDateTime>(arguments[0].get()))
600 601 602 603 604 605
                throw Exception{
                    "Illegal type " + arguments[0]->getName() + " of argument of function " + getName() +
                    ". Should be a date or a date with time", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
        }
        else if (arguments.size() == 2)
        {
606 607
            if (!checkDataType<DataTypeDateTime>(arguments[0].get())
                || !checkDataType<DataTypeString>(arguments[1].get()))
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
                throw Exception{
                    "Function " + getName() + " supports 1 or 2 arguments. The 1st argument "
                    "must be of type Date or DateTime. The 2nd argument (optional) must be "
                    "a constant string with timezone name. The timezone argument is allowed "
                    "only when the 1st argument has the type DateTime",
                    ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
        }
        else
            throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
                + toString(arguments.size()) + ", should be 1 or 2",
                ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

        return std::make_shared<ToDataType>();
    }

623 624 625
    bool useDefaultImplementationForConstants() const override { return true; }
    ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; }

626 627
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
628
        const IDataType * from_type = block.getByPosition(arguments[0]).type.get();
629

630
        if (checkDataType<DataTypeDate>(from_type))
631
            DateTimeTransformImpl<DataTypeDate::FieldType, typename ToDataType::FieldType, Transform>::execute(block, arguments, result);
632
        else if (checkDataType<DataTypeDateTime>(from_type))
633
            DateTimeTransformImpl<DataTypeDateTime::FieldType, typename ToDataType::FieldType, Transform>::execute(block, arguments, result);
634
        else
635
            throw Exception("Illegal type " + block.getByPosition(arguments[0]).type->getName() + " of argument of function " + getName(),
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }


    bool hasInformationAboutMonotonicity() const override
    {
        return true;
    }

    Monotonicity getMonotonicityForRange(const IDataType & type, const Field & left, const Field & right) const override
    {
        IFunction::Monotonicity is_monotonic { true };
        IFunction::Monotonicity is_not_monotonic;

        if (std::is_same<typename Transform::FactorTransform, ZeroTransform>::value)
651 652
        {
            is_monotonic.is_always_monotonic = true;
653
            return is_monotonic;
654
        }
655

F
f1yegor 已提交
656
        /// This method is called only if the function has one argument. Therefore, we do not care about the non-local time zone.
657 658 659 660 661
        const DateLUTImpl & date_lut = DateLUT::instance();

        if (left.isNull() || right.isNull())
            return is_not_monotonic;

F
f1yegor 已提交
662
        /// The function is monotonous on the [left, right] segment, if the factor transformation returns the same values for them.
663

664
        if (checkAndGetDataType<DataTypeDate>(&type))
665 666 667 668 669 670 671 672 673 674 675 676
        {
            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;
        }
    }
A
Alexey Milovidov 已提交
677 678 679
};


680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945
struct AddSecondsImpl
{
    static constexpr auto name = "addSeconds";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return t + delta;
    }

    static inline UInt32 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.fromDayNum(DayNum_t(d)) + delta;
    }
};

struct AddMinutesImpl
{
    static constexpr auto name = "addMinutes";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return t + delta * 60;
    }

    static inline UInt32 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.fromDayNum(DayNum_t(d)) + delta * 60;
    }
};

struct AddHoursImpl
{
    static constexpr auto name = "addHours";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return t + delta * 3600;
    }

    static inline UInt32 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.fromDayNum(DayNum_t(d)) + delta * 3600;
    }
};

struct AddDaysImpl
{
    static constexpr auto name = "addDays";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addDays(t, delta);
    }

    static inline UInt16 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return d + delta;
    }
};

struct AddWeeksImpl
{
    static constexpr auto name = "addWeeks";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addWeeks(t, delta);
    }

    static inline UInt16 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return d + delta * 7;
    }
};

struct AddMonthsImpl
{
    static constexpr auto name = "addMonths";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addMonths(t, delta);
    }

    static inline UInt16 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addMonths(DayNum_t(d), delta);
    }
};

struct AddYearsImpl
{
    static constexpr auto name = "addYears";

    static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addYears(t, delta);
    }

    static inline UInt16 execute(UInt16 d, Int64 delta, const DateLUTImpl & time_zone)
    {
        return time_zone.addYears(DayNum_t(d), delta);
    }
};

template <typename FromType, typename ToType, typename Transform>
struct Adder
{
    static void vector_vector(const PaddedPODArray<FromType> & vec_from, PaddedPODArray<ToType> & vec_to, const IColumn & delta, const DateLUTImpl & time_zone)
    {
        size_t size = vec_from.size();
        vec_to.resize(size);

        for (size_t i = 0; i < size; ++i)
            vec_to[i] = Transform::execute(vec_from[i], delta.getInt(i), time_zone);
    }

    static void vector_constant(const PaddedPODArray<FromType> & vec_from, PaddedPODArray<ToType> & vec_to, Int64 delta, const DateLUTImpl & time_zone)
    {
        size_t size = vec_from.size();
        vec_to.resize(size);

        for (size_t i = 0; i < size; ++i)
            vec_to[i] = Transform::execute(vec_from[i], delta, time_zone);
    }

    static void constant_vector(const FromType & from, PaddedPODArray<ToType> & vec_to, const IColumn & delta, const DateLUTImpl & time_zone)
    {
        size_t size = delta.size();
        vec_to.resize(size);

        for (size_t i = 0; i < size; ++i)
            vec_to[i] = Transform::execute(from, delta.getInt(i), time_zone);
    }
};


template <typename FromType, typename Transform>
struct DateTimeAddIntervalImpl
{
    static void execute(Block & block, const ColumnNumbers & arguments, size_t result)
    {
        using ToType = decltype(Transform::execute(FromType(), 0, std::declval<DateLUTImpl>()));
        using Op = Adder<FromType, ToType, Transform>;

        const ColumnConst * time_zone_column = nullptr;

        if (arguments.size() == 3)
        {
            time_zone_column = checkAndGetColumnConst<ColumnString>(block.getByPosition(arguments[2]).column.get());

            if (!time_zone_column)
                throw Exception("Illegal column " + block.getByPosition(arguments[2]).column->getName()
                    + " of second (time zone) argument of function " + Transform::name + ", must be constant string",
                    ErrorCodes::ILLEGAL_COLUMN);
        }

        const DateLUTImpl & time_zone = time_zone_column
            ? DateLUT::instance(time_zone_column->getValue<String>())
            : DateLUT::instance();

        const ColumnPtr source_col = block.getByPosition(arguments[0]).column;

        if (const auto * sources = checkAndGetColumn<ColumnVector<FromType>>(source_col.get()))
        {
            auto col_to = std::make_shared<ColumnVector<ToType>>();
            block.getByPosition(result).column = col_to;

            const IColumn & delta_column = *block.getByPosition(arguments[1]).column;

            if (const auto * delta_const_column = typeid_cast<const ColumnConst *>(&delta_column))
                Op::vector_constant(sources->getData(), col_to->getData(), delta_const_column->getValue<Int64>(), time_zone);
            else
                Op::vector_vector(sources->getData(), col_to->getData(), delta_column, time_zone);
        }
        else if (const auto * sources = checkAndGetColumnConst<ColumnVector<FromType>>(source_col.get()))
        {
            auto col_to = std::make_shared<ColumnVector<ToType>>();
            block.getByPosition(result).column = col_to;
            Op::constant_vector(sources->template getValue<FromType>(), col_to->getData(), *block.getByPosition(arguments[1]).column, time_zone);
        }
        else
        {
            throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName()
                + " of first argument of function " + Transform::name,
                ErrorCodes::ILLEGAL_COLUMN);
        }
    }
};


template <typename Transform>
class FunctionDateOrDateTimeAddInterval : public IFunction
{
public:
    static constexpr auto name = Transform::name;
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionDateOrDateTimeAddInterval>(); };

    String getName() const override
    {
        return name;
    }

    bool isVariadic() const override { return true; }
    size_t getNumberOfArguments() const override { return 0; }

    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
        if (arguments.size() != 2 && arguments.size() != 3)
            throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
                + toString(arguments.size()) + ", should be 2 or 3",
                ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

        if (!arguments[1]->behavesAsNumber())
            throw Exception("Second argument for function " + getName() + " (delta) must be number",
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

        if (arguments.size() == 2)
        {
            if (!checkDataType<DataTypeDate>(arguments[0].get())
                && !checkDataType<DataTypeDateTime>(arguments[0].get()))
                throw Exception{
                    "Illegal type " + arguments[0]->getName() + " of argument of function " + getName() +
                    ". Should be a date or a date with time", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
        }
        else
        {
            if (!checkDataType<DataTypeDateTime>(arguments[0].get())
                || !checkDataType<DataTypeString>(arguments[1].get()))
                throw Exception{
                    "Function " + getName() + " supports 2 or 3 arguments. The 1st argument "
                    "must be of type Date or DateTime. The 2nd argument must be number. "
                    "The 3rd argument (optional) must be "
                    "a constant string with timezone name. The timezone argument is allowed "
                    "only when the 1st argument has the type DateTime",
                    ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
        }

        if (checkDataType<DataTypeDate>(arguments[0].get()))
            return std::make_shared<typename std::conditional<std::is_same<
                decltype(Transform::execute(DataTypeDate::FieldType(), 0, std::declval<DateLUTImpl>())), UInt16>::value,
                DataTypeDate, DataTypeDateTime>::type>();
        else
            return std::make_shared<typename std::conditional<std::is_same<
                decltype(Transform::execute(DataTypeDateTime::FieldType(), 0, std::declval<DateLUTImpl>())), UInt16>::value,
                DataTypeDate, DataTypeDateTime>::type>();
    }

    bool useDefaultImplementationForConstants() const override { return true; }
    ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {2}; }

    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
        const IDataType * from_type = block.getByPosition(arguments[0]).type.get();

        if (checkDataType<DataTypeDate>(from_type))
            DateTimeAddIntervalImpl<DataTypeDate::FieldType, Transform>::execute(block, arguments, result);
        else if (checkDataType<DataTypeDateTime>(from_type))
            DateTimeAddIntervalImpl<DataTypeDateTime::FieldType, Transform>::execute(block, arguments, result);
        else
            throw Exception("Illegal type " + block.getByPosition(arguments[0]).type->getName() + " of argument of function " + getName(),
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
    }
};


F
f1yegor 已提交
946
/// Get the current time. (It is a constant, it is evaluated once for the entire query.)
947 948 949
class FunctionNow : public IFunction
{
public:
950 951
    static constexpr auto name = "now";
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionNow>(); };
952

953 954 955 956
    String getName() const override
    {
        return name;
    }
957

958
    size_t getNumberOfArguments() const override { return 0; }
959

960 961 962 963
    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
        return std::make_shared<DataTypeDateTime>();
    }
964

965 966
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
967
        block.getByPosition(result).column = DataTypeUInt32().createConstColumn(
968
            block.rows(),
P
proller 已提交
969
            static_cast<UInt64>(time(0)));
970
    }
971 972 973
};


974 975 976
class FunctionToday : public IFunction
{
public:
977 978
    static constexpr auto name = "today";
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionToday>(); };
979

980 981 982 983
    String getName() const override
    {
        return name;
    }
984

985
    size_t getNumberOfArguments() const override { return 0; }
986

987 988 989 990
    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
        return std::make_shared<DataTypeDate>();
    }
991

992 993
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
994
        block.getByPosition(result).column = DataTypeUInt16().createConstColumn(
995
            block.rows(),
996
            UInt64(DateLUT::instance().toDayNum(time(0))));
997
    }
998 999 1000 1001 1002 1003
};


class FunctionYesterday : public IFunction
{
public:
1004 1005
    static constexpr auto name = "yesterday";
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionYesterday>(); };
1006

1007 1008 1009 1010
    String getName() const override
    {
        return name;
    }
1011

1012
    size_t getNumberOfArguments() const override { return 0; }
1013

1014 1015 1016 1017
    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
        return std::make_shared<DataTypeDate>();
    }
1018

1019 1020
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
1021
        block.getByPosition(result).column = DataTypeUInt16().createConstColumn(
1022
            block.rows(),
1023
            UInt64(DateLUT::instance().toDayNum(time(0)) - 1));
1024
    }
1025 1026 1027
};


1028 1029 1030
class FunctionTimeSlot : public IFunction
{
public:
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
    static constexpr auto name = "timeSlot";
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionTimeSlot>(); };

    String getName() const override
    {
        return name;
    }

    size_t getNumberOfArguments() const override { return 1; }

    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
1043
        if (!checkDataType<DataTypeDateTime>(arguments[0].get()))
1044 1045 1046 1047 1048 1049
            throw Exception("Illegal type " + arguments[0]->getName() + " of first argument of function " + getName() + ". Must be DateTime.",
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

        return std::make_shared<DataTypeDateTime>();
    }

1050 1051
    bool useDefaultImplementationForConstants() const override { return true; }

1052 1053
    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
1054
        if (const ColumnUInt32 * times = typeid_cast<const ColumnUInt32 *>(block.getByPosition(arguments[0]).column.get()))
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
        {
            auto res = std::make_shared<ColumnUInt32>();
            ColumnPtr res_holder = res;
            ColumnUInt32::Container_t & res_vec = res->getData();
            const ColumnUInt32::Container_t & vec = times->getData();

            size_t size = vec.size();
            res_vec.resize(size);

            for (size_t i = 0; i < size; ++i)
                res_vec[i] = vec[i] / TIME_SLOT_SIZE * TIME_SLOT_SIZE;

1067
            block.getByPosition(result).column = res_holder;
1068 1069
        }
        else
1070
            throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName()
1071 1072 1073
                    + " of argument of function " + getName(),
                ErrorCodes::ILLEGAL_COLUMN);
    }
1074 1075 1076 1077 1078 1079
};


template <typename DurationType>
struct TimeSlotsImpl
{
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
    static void vector_vector(
        const PaddedPODArray<UInt32> & starts, const PaddedPODArray<DurationType> & durations,
        PaddedPODArray<UInt32> & result_values, ColumnArray::Offsets_t & result_offsets)
    {
        size_t size = starts.size();

        result_offsets.resize(size);
        result_values.reserve(size);

        ColumnArray::Offset_t current_offset = 0;
        for (size_t i = 0; i < size; ++i)
        {
            for (UInt32 value = starts[i] / TIME_SLOT_SIZE; value <= (starts[i] + durations[i]) / TIME_SLOT_SIZE; ++value)
            {
                result_values.push_back(value * TIME_SLOT_SIZE);
                ++current_offset;
            }

            result_offsets[i] = current_offset;
        }
    }

    static void vector_constant(
        const PaddedPODArray<UInt32> & starts, DurationType duration,
        PaddedPODArray<UInt32> & result_values, ColumnArray::Offsets_t & result_offsets)
    {
        size_t size = starts.size();

        result_offsets.resize(size);
        result_values.reserve(size);

        ColumnArray::Offset_t current_offset = 0;
        for (size_t i = 0; i < size; ++i)
        {
            for (UInt32 value = starts[i] / TIME_SLOT_SIZE; value <= (starts[i] + duration) / TIME_SLOT_SIZE; ++value)
            {
                result_values.push_back(value * TIME_SLOT_SIZE);
                ++current_offset;
            }

            result_offsets[i] = current_offset;
        }
    }

    static void constant_vector(
        UInt32 start, const PaddedPODArray<DurationType> & durations,
        PaddedPODArray<UInt32> & result_values, ColumnArray::Offsets_t & result_offsets)
    {
        size_t size = durations.size();

        result_offsets.resize(size);
        result_values.reserve(size);

        ColumnArray::Offset_t current_offset = 0;
        for (size_t i = 0; i < size; ++i)
        {
            for (UInt32 value = start / TIME_SLOT_SIZE; value <= (start + durations[i]) / TIME_SLOT_SIZE; ++value)
            {
                result_values.push_back(value * TIME_SLOT_SIZE);
                ++current_offset;
            }

            result_offsets[i] = current_offset;
        }
    }

    static void constant_constant(
        UInt32 start, DurationType duration,
        Array & result)
    {
        for (UInt32 value = start / TIME_SLOT_SIZE; value <= (start + duration) / TIME_SLOT_SIZE; ++value)
            result.push_back(static_cast<UInt64>(value * TIME_SLOT_SIZE));
    }
1153 1154 1155 1156 1157 1158
};


class FunctionTimeSlots : public IFunction
{
public:
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
    static constexpr auto name = "timeSlots";
    static FunctionPtr create(const Context & context) { return std::make_shared<FunctionTimeSlots>(); };

    String getName() const override
    {
        return name;
    }

    size_t getNumberOfArguments() const override { return 2; }

    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
    {
1171
        if (!checkDataType<DataTypeDateTime>(arguments[0].get()))
1172 1173 1174
            throw Exception("Illegal type " + arguments[0]->getName() + " of first argument of function " + getName() + ". Must be DateTime.",
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

1175
        if (!checkDataType<DataTypeUInt32>(arguments[1].get()))
1176 1177 1178 1179 1180 1181 1182 1183
            throw Exception("Illegal type " + arguments[1]->getName() + " of second argument of function " + getName() + ". Must be UInt32.",
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

        return std::make_shared<DataTypeArray>(std::make_shared<DataTypeDateTime>());
    }

    void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result) override
    {
1184 1185
        auto starts = checkAndGetColumn<ColumnUInt32>(block.getByPosition(arguments[0]).column.get());
        auto const_starts = checkAndGetColumnConst<ColumnUInt32>(block.getByPosition(arguments[0]).column.get());
1186

1187 1188
        auto durations = checkAndGetColumn<ColumnUInt32>(block.getByPosition(arguments[1]).column.get());
        auto const_durations = checkAndGetColumnConst<ColumnUInt32>(block.getByPosition(arguments[1]).column.get());
1189 1190 1191 1192 1193 1194 1195 1196

        auto res = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt32>());
        ColumnPtr res_holder = res;
        ColumnUInt32::Container_t & res_values = typeid_cast<ColumnUInt32 &>(res->getData()).getData();

        if (starts && durations)
        {
            TimeSlotsImpl<UInt32>::vector_vector(starts->getData(), durations->getData(), res_values, res->getOffsets());
1197
            block.getByPosition(result).column = res_holder;
1198 1199 1200
        }
        else if (starts && const_durations)
        {
1201 1202
            TimeSlotsImpl<UInt32>::vector_constant(starts->getData(), const_durations->getValue<UInt32>(), res_values, res->getOffsets());
            block.getByPosition(result).column = res_holder;
1203 1204 1205
        }
        else if (const_starts && durations)
        {
1206 1207
            TimeSlotsImpl<UInt32>::constant_vector(const_starts->getValue<UInt32>(), durations->getData(), res_values, res->getOffsets());
            block.getByPosition(result).column = res_holder;
1208 1209 1210 1211
        }
        else if (const_starts && const_durations)
        {
            Array const_res;
1212 1213
            TimeSlotsImpl<UInt32>::constant_constant(const_starts->getValue<UInt32>(), const_durations->getValue<UInt32>(), const_res);
            block.getByPosition(result).column = block.getByPosition(result).type->createConstColumn(block.rows(), const_res);
1214 1215
        }
        else
1216 1217
            throw Exception("Illegal columns " + block.getByPosition(arguments[0]).column->getName()
                    + ", " + block.getByPosition(arguments[1]).column->getName()
1218 1219 1220 1221 1222 1223
                    + " of arguments of function " + getName(),
                ErrorCodes::ILLEGAL_COLUMN);
    }
};


1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
using FunctionToYear = FunctionDateOrDateTimeToSomething<DataTypeUInt16, ToYearImpl>;
using FunctionToMonth = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToMonthImpl>;
using FunctionToDayOfMonth = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToDayOfMonthImpl>;
using FunctionToDayOfWeek = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToDayOfWeekImpl>;
using FunctionToHour = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToHourImpl>;
using FunctionToMinute = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToMinuteImpl>;
using FunctionToSecond = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToSecondImpl>;
using FunctionToStartOfDay = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToStartOfDayImpl>;
using FunctionToMonday = FunctionDateOrDateTimeToSomething<DataTypeDate, ToMondayImpl>;
using FunctionToStartOfMonth = FunctionDateOrDateTimeToSomething<DataTypeDate, ToStartOfMonthImpl>;
using FunctionToStartOfQuarter = FunctionDateOrDateTimeToSomething<DataTypeDate, ToStartOfQuarterImpl>;
using FunctionToStartOfYear = FunctionDateOrDateTimeToSomething<DataTypeDate, ToStartOfYearImpl>;
using FunctionToStartOfMinute = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToStartOfMinuteImpl>;
using FunctionToStartOfFiveMinute = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToStartOfFiveMinuteImpl>;
using FunctionToStartOfHour = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToStartOfHourImpl>;
using FunctionToTime = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToTimeImpl>;

using FunctionToRelativeYearNum = FunctionDateOrDateTimeToSomething<DataTypeUInt16, ToRelativeYearNumImpl>;
using FunctionToRelativeMonthNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeMonthNumImpl>;
using FunctionToRelativeWeekNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeWeekNumImpl>;
using FunctionToRelativeDayNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeDayNumImpl>;

using FunctionToRelativeHourNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeHourNumImpl>;
using FunctionToRelativeMinuteNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeMinuteNumImpl>;
using FunctionToRelativeSecondNum = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToRelativeSecondNumImpl>;

using FunctionToYYYYMM = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToYYYYMMImpl>;
using FunctionToYYYYMMDD = FunctionDateOrDateTimeToSomething<DataTypeUInt32, ToYYYYMMDDImpl>;
using FunctionToYYYYMMDDhhmmss = FunctionDateOrDateTimeToSomething<DataTypeUInt64, ToYYYYMMDDhhmmssImpl>;

using FunctionAddSeconds = FunctionDateOrDateTimeAddInterval<AddSecondsImpl>;
using FunctionAddMinutes = FunctionDateOrDateTimeAddInterval<AddMinutesImpl>;
using FunctionAddHours = FunctionDateOrDateTimeAddInterval<AddHoursImpl>;
using FunctionAddDays = FunctionDateOrDateTimeAddInterval<AddDaysImpl>;
using FunctionAddWeeks = FunctionDateOrDateTimeAddInterval<AddWeeksImpl>;
using FunctionAddMonths = FunctionDateOrDateTimeAddInterval<AddMonthsImpl>;
using FunctionAddYears = FunctionDateOrDateTimeAddInterval<AddYearsImpl>;
1261

A
Alexey Milovidov 已提交
1262
}