More test

This commit is contained in:
Vasily Nemkov 2019-10-04 16:49:34 +03:00
parent bda2179dc3
commit a3548b08a9

View File

@ -3,10 +3,11 @@
import re
import itertools
import sys
# Create SQL statement to verify dateTime64 is accepted as argument to functions taking DateTime.
functions="""
# toTimeZone({datetime}, 'UTC') -- does not work
toTimeZone({datetime}, 'UTC')
toYear({datetime})
toQuarter({datetime})
toMonth({datetime})
@ -22,18 +23,18 @@ toStartOfISOYear({datetime})
toStartOfQuarter({datetime})
toStartOfMonth({datetime})
toMonday({datetime})
# toStartOfWeek({datetime}) -- there is no such function
toStartOfWeek({datetime})
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)
# Do not work 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})
@ -45,33 +46,39 @@ toRelativeMinuteNum({datetime})
toRelativeSecondNum({datetime})
toISOYear({datetime})
toISOWeek({datetime})
# toWeek({datetime}) -- Unknown function toWeek
# toYearWeek({datetime}) -- Unknown function toYearWeek
toWeek({datetime})
toYearWeek({datetime})
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)
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)
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 Date)
CAST({datetime} as UInt64)
CAST({datetime} as DateTime64(0))
CAST({datetime} as DateTime64(3))
CAST({datetime} as DateTime64(6))
CAST({datetime} as DateTime64(9))
CAST({datetime} as DateTime64(12))
CAST({datetime} as DateTime64(18))
formatDateTime({datetime}, '%C %d %D %e %F %H %I %j %m %M %n %p %R %S %t %T %u %V %w %y %Y %%')
""".splitlines()
@ -85,7 +92,7 @@ extra_ops =\
[
# With same type:
(
'{{datetime}} {op} {{datetime}}',
['{{datetime}} {op} {{datetime}}'],
{
'op':
[
@ -101,7 +108,10 @@ extra_ops =\
),
# With other DateTime types:
(
'{{datetime}} {op} {arg}',
[
'{{datetime}} {op} {arg}',
'{arg} {op} {{datetime}}'
],
{
'op':
[
@ -118,7 +128,10 @@ extra_ops =\
),
# With arithmetic types
(
'{{datetime}} {op} {arg}',
[
'{{datetime}} {op} {arg}',
'{arg} {op} {{datetime}}'
],
{
'op':
[
@ -143,17 +156,32 @@ extra_ops =\
]
# Expand extra_ops here
for f, args in extra_ops:
for funcs, 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 funcs:
for args_vals in itertools.product(*args.values()):
result_func = func.format(**dict(zip(args_keys, args_vals)))
functions.append(result_func)
datetime64_args = ['now64(0)', 'now64(3)', 'now64(6)', 'now64(9)', 'now64(12)', 'now64(15)']
datetime64_args = [ #'now64(0)', 'now64(3)', 'now64(6)', 'now64(9)', 'now64(17)']
'now64(3)']
if sys.version_info[0] > 2:
escape_string_codec = 'unicode_escape'
else:
escape_string_codec = 'string-escape'
def escape_string(s):
return s.encode(escape_string_codec).decode('utf-8')
# TODO: use string.Template here to allow lines that do not contain type, like: SELECT CAST(toDateTime64(1234567890), 'DateTime64')
for func in functions:
for dt in datetime64_args:
f = func.format(datetime=dt)
print("""SELECT '{function}';""".format(function=f))
print("""SELECT {function};""".format(function=f))
f32 = func.format(datetime='now()')
f64 = func.format(datetime=dt)
f = "({f32}) == ({f64})".format(f32=f32, f64=f64)
print("""SELECT '{f64}';""".format(f64=escape_string(f64)))
print("""SELECT {f32};""".format(f32=f32))
print("""SELECT {f64};""".format(f64=f64))
# print("""SELECT {f};""".format(f=f))
print("""SELECT '-----------------------------------------------------------------------------------';""")