mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
153 lines
4.3 KiB
Python
Executable File
153 lines
4.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
import re
|
|
import itertools
|
|
|
|
# Create SQL statement to verify dateTime64 is accepted as argument to functions taking DateTime.
|
|
functions="""
|
|
# toTimeZone({datetime}, 'UTC') -- does not work
|
|
toYear({datetime})
|
|
toQuarter({datetime})
|
|
toMonth({datetime})
|
|
toDayOfYear({datetime})
|
|
toDayOfMonth({datetime})
|
|
toDayOfWeek({datetime})
|
|
toHour({datetime})
|
|
toMinute({datetime})
|
|
toSecond({datetime})
|
|
toUnixTimestamp({datetime})
|
|
toStartOfYear({datetime})
|
|
toStartOfISOYear({datetime})
|
|
toStartOfQuarter({datetime})
|
|
toStartOfMonth({datetime})
|
|
toMonday({datetime})
|
|
# toStartOfWeek({datetime}) -- there is no such function
|
|
toStartOfDay({datetime})
|
|
toStartOfHour({datetime})
|
|
toStartOfMinute({datetime})
|
|
toStartOfFiveMinute({datetime})
|
|
toStartOfTenMinutes({datetime})
|
|
toStartOfFifteenMinutes({datetime})
|
|
# Do not workk with DateTime64
|
|
# toStartOfInterval({datetime}, INTERVAL 1 year)
|
|
# toStartOfInterval({datetime}, INTERVAL 1 month)
|
|
# toStartOfInterval({datetime}, INTERVAL 1 day)
|
|
# toStartOfInterval({datetime}, INTERVAL 15 minute)
|
|
toTime({datetime})
|
|
toRelativeYearNum({datetime})
|
|
toRelativeQuarterNum({datetime})
|
|
toRelativeMonthNum({datetime})
|
|
toRelativeWeekNum({datetime})
|
|
toRelativeDayNum({datetime})
|
|
toRelativeHourNum({datetime})
|
|
toRelativeMinuteNum({datetime})
|
|
toRelativeSecondNum({datetime})
|
|
toISOYear({datetime})
|
|
toISOWeek({datetime})
|
|
# toWeek({datetime}) -- Unknown function toWeek
|
|
# toYearWeek({datetime}) -- Unknown function toYearWeek
|
|
timeSlot({datetime})
|
|
toYYYYMM({datetime})
|
|
toYYYYMMDD({datetime})
|
|
toYYYYMMDDhhmmss({datetime})
|
|
# -- Illegal type DateTime64 of argument of function addYears
|
|
# addYears({datetime}, 1)
|
|
# addMonths({datetime}, 1)
|
|
# addWeeks({datetime}, 1)
|
|
# addDays({datetime}, 1)
|
|
# addHours({datetime}, 1)
|
|
# addMinutes({datetime}, 1)
|
|
# addSeconds({datetime}, 1)
|
|
# addQuarters({datetime}, 1)
|
|
# -- Illegal type DateTime64 of argument of function subtractYears.
|
|
# subtractYears({datetime}, 1)
|
|
# subtractMonths({datetime}, 1)
|
|
# subtractWeeks({datetime}, 1)
|
|
# subtractDays({datetime}, 1)
|
|
# subtractHours({datetime}, 1)
|
|
# subtractMinutes({datetime}, 1)
|
|
# subtractSeconds({datetime}, 1)
|
|
# subtractQuarters({datetime}, 1)
|
|
CAST({datetime} as DateTime)
|
|
CAST({datetime} as UInt64)
|
|
formatDateTime({datetime}, '%C %d %D %e %F %H %I %j %m %M %n %p %R %S %t %T %u %V %w %y %Y %%')
|
|
""".splitlines()
|
|
|
|
# filter out empty lines and commented out lines
|
|
COMMENTED_OUT_LINE_RE = re.compile(r"^\s*#")
|
|
functions = list(filter(lambda f: len(f) != 0 and COMMENTED_OUT_LINE_RE.match(f) == None, functions))
|
|
|
|
# Expanded to cartesian product of all arguments.
|
|
# NOTE: {{datetime}} to be turned into {datetime} after str.format() for keys (format string), but not for list of values!
|
|
extra_ops =\
|
|
[
|
|
# With same type:
|
|
(
|
|
'{{datetime}} {op} {{datetime}}',
|
|
{
|
|
'op':
|
|
[
|
|
'- ', # does not work, but should it?
|
|
'+ ', # does not work, but should it?
|
|
'!=', '==', # how do we expect this to work?
|
|
'< ',
|
|
'<=',
|
|
'> ',
|
|
'>='
|
|
]
|
|
}
|
|
),
|
|
# With other DateTime types:
|
|
(
|
|
'{{datetime}} {op} {arg}',
|
|
{
|
|
'op':
|
|
[
|
|
'-', # does not work, but should it?
|
|
'!=', '==', # how do we expect this to work?
|
|
# these are naturally expected to work, but they don't:
|
|
'< ',
|
|
'<=',
|
|
'> ',
|
|
'>='
|
|
],
|
|
'arg': ['now()'],
|
|
}
|
|
),
|
|
# With arithmetic types
|
|
(
|
|
'{{datetime}} {op} {arg}',
|
|
{
|
|
'op':
|
|
[
|
|
'+ ',
|
|
'- ',
|
|
'==',
|
|
'!=',
|
|
'< ',
|
|
'<=',
|
|
'> ',
|
|
'>='
|
|
],
|
|
'arg':
|
|
[
|
|
'1',
|
|
'-1',
|
|
'toInt64(1)',
|
|
'toInt64(-1)'
|
|
],
|
|
},
|
|
),
|
|
]
|
|
|
|
# Expand extra_ops here
|
|
for f, args in extra_ops:
|
|
args_keys = args.keys()
|
|
for args_vals in itertools.product(*args.values()):
|
|
func = f.format(**dict(zip(args_keys, args_vals)))
|
|
functions.append(func)
|
|
|
|
for func in functions:
|
|
f = func.format(datetime="now64()")
|
|
print("""SELECT {function};""".format(function=f)) |