mirror of
https://github.com/apache/superset.git
synced 2024-09-12 16:49:40 -04:00
chore(druid): Explicitly cast col to TIMESTAMP (#17101)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
parent
ae4ced8da6
commit
565ee2318d
@ -40,27 +40,27 @@ class DruidEngineSpec(BaseEngineSpec):
|
|||||||
allows_subqueries = True
|
allows_subqueries = True
|
||||||
|
|
||||||
_time_grain_expressions = {
|
_time_grain_expressions = {
|
||||||
None: "{col}",
|
None: "CAST({col} AS TIMESTAMP)",
|
||||||
"PT1S": "TIME_FLOOR({col}, 'PT1S')",
|
"PT1S": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT1S')",
|
||||||
"PT5S": "TIME_FLOOR({col}, 'PT5S')",
|
"PT5S": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT5S')",
|
||||||
"PT30S": "TIME_FLOOR({col}, 'PT30S')",
|
"PT30S": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT30S')",
|
||||||
"PT1M": "TIME_FLOOR({col}, 'PT1M')",
|
"PT1M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT1M')",
|
||||||
"PT5M": "TIME_FLOOR({col}, 'PT5M')",
|
"PT5M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT5M')",
|
||||||
"PT10M": "TIME_FLOOR({col}, 'PT10M')",
|
"PT10M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT10M')",
|
||||||
"PT15M": "TIME_FLOOR({col}, 'PT15M')",
|
"PT15M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT15M')",
|
||||||
"PT30M": "TIME_FLOOR({col}, 'PT30M')",
|
"PT30M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT30M')",
|
||||||
"PT1H": "TIME_FLOOR({col}, 'PT1H')",
|
"PT1H": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT1H')",
|
||||||
"PT6H": "TIME_FLOOR({col}, 'PT6H')",
|
"PT6H": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT6H')",
|
||||||
"P1D": "TIME_FLOOR({col}, 'P1D')",
|
"P1D": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'P1D')",
|
||||||
"P1W": "TIME_FLOOR({col}, 'P1W')",
|
"P1W": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'P1W')",
|
||||||
"P1M": "TIME_FLOOR({col}, 'P1M')",
|
"P1M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'P1M')",
|
||||||
"P3M": "TIME_FLOOR({col}, 'P3M')",
|
"P3M": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'P3M')",
|
||||||
"P1Y": "TIME_FLOOR({col}, 'P1Y')",
|
"P1Y": "TIME_FLOOR(CAST({col} AS TIMESTAMP), 'P1Y')",
|
||||||
"P1W/1970-01-03T00:00:00Z": (
|
"P1W/1970-01-03T00:00:00Z": (
|
||||||
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT({col}, 'P1D', 1), 'P1W'), 'P1D', 5)"
|
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST({col} AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', 5)" # pylint: disable=line-too-long
|
||||||
),
|
),
|
||||||
"1969-12-28T00:00:00Z/P1W": (
|
"1969-12-28T00:00:00Z/P1W": (
|
||||||
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT({col}, 'P1D', 1), 'P1W'), 'P1D', -1)"
|
"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST({col} AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', -1)" # pylint: disable=line-too-long
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ class TestDruidDbEngineSpec(TestDbEngineSpec):
|
|||||||
col = "__time"
|
col = "__time"
|
||||||
sqla_col = column(col)
|
sqla_col = column(col)
|
||||||
test_cases = {
|
test_cases = {
|
||||||
"PT1S": f"TIME_FLOOR({col}, 'PT1S')",
|
"PT1S": f"TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT1S')",
|
||||||
"PT5M": f"TIME_FLOOR({col}, 'PT5M')",
|
"PT5M": f"TIME_FLOOR(CAST({col} AS TIMESTAMP), 'PT5M')",
|
||||||
"P1W/1970-01-03T00:00:00Z": f"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT({col}, 'P1D', 1), 'P1W'), 'P1D', 5)",
|
"P1W/1970-01-03T00:00:00Z": f"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST({col} AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', 5)",
|
||||||
"1969-12-28T00:00:00Z/P1W": f"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT({col}, 'P1D', 1), 'P1W'), 'P1D', -1)",
|
"1969-12-28T00:00:00Z/P1W": f"TIME_SHIFT(TIME_FLOOR(TIME_SHIFT(CAST({col} AS TIMESTAMP), 'P1D', 1), 'P1W'), 'P1D', -1)",
|
||||||
}
|
}
|
||||||
for grain, expected in test_cases.items():
|
for grain, expected in test_cases.items():
|
||||||
actual = DruidEngineSpec.get_timestamp_expr(
|
actual = DruidEngineSpec.get_timestamp_expr(
|
||||||
|
Loading…
Reference in New Issue
Block a user