Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render date literals as strings in time range filters #724

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230814-231516.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Remove barrier to partition pruning certain time partition filter predicates
time: 2023-08-14T23:15:16.658262-07:00
custom:
Author: tlento
Issue: "712"
13 changes: 4 additions & 9 deletions metricflow/plan_conversion/dataflow_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
)
from metricflow.sql.sql_exprs import (
SqlBetweenExpression,
SqlCastToTimestampExpression,
SqlColumnReference,
SqlColumnReferenceExpression,
SqlDateTruncExpression,
Expand Down Expand Up @@ -124,15 +123,11 @@ def _make_time_range_comparison_expr(
column_name=column_alias,
)
),
start_expr=SqlCastToTimestampExpression(
arg=SqlStringLiteralExpression(
literal_value=time_range_constraint.start_time.strftime(ISO8601_PYTHON_FORMAT),
)
start_expr=SqlStringLiteralExpression(
literal_value=time_range_constraint.start_time.strftime(ISO8601_PYTHON_FORMAT),
),
end_expr=SqlCastToTimestampExpression(
arg=SqlStringLiteralExpression(
literal_value=time_range_constraint.end_time.strftime(ISO8601_PYTHON_FORMAT),
)
end_expr=SqlStringLiteralExpression(
literal_value=time_range_constraint.end_time.strftime(ISO8601_PYTHON_FORMAT),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ FROM (
) subq_0
) subq_1
) subq_2
WHERE subq_2.metric_time__day BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-02' AS DATETIME)
WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ SELECT
, ds AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_10001
WHERE ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-02' AS DATETIME)
WHERE ds BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2000-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC(created_at, month) AS ds__month
, SUM(revenue) AS revenue_all_time
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2000-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE created_at BETWEEN '2000-01-01' AND '2020-01-01'
GROUP BY
ds__month
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2019-12-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE subq_1.metric_time__day BETWEEN '2019-12-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC(created_at, month) AS ds__month
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2019-12-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE created_at BETWEEN '2019-12-01' AND '2020-01-01'
GROUP BY
ds__month
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2021-01-01' AS DATETIME)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ FROM (
FROM ***************************.fct_bookings bookings_source_src_10001
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_2
) subq_3
) subq_4
Expand Down Expand Up @@ -327,7 +327,7 @@ CROSS JOIN (
FROM ***************************.dim_listings_latest listings_latest_src_10004
) subq_6
) subq_7
WHERE subq_7.metric_time__day BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_8
) subq_9
) subq_10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM (
SELECT
SUM(1) AS bookings
FROM ***************************.fct_bookings bookings_source_src_10001
WHERE ds BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE ds BETWEEN '2020-01-01' AND '2020-01-01'
) subq_17
CROSS JOIN (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -26,5 +26,5 @@ CROSS JOIN (
SELECT
SUM(1) AS listings
FROM ***************************.dim_listings_latest listings_latest_src_10004
WHERE created_at BETWEEN CAST('2020-01-01' AS DATETIME) AND CAST('2020-01-01' AS DATETIME)
WHERE created_at BETWEEN '2020-01-01' AND '2020-01-01'
) subq_23
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ FROM (
) subq_0
) subq_1
) subq_2
WHERE subq_2.metric_time__day BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-02' AS TIMESTAMP)
WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ SELECT
, ds AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_10001
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-02' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2000-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC('month', created_at) AS ds__month
, SUM(revenue) AS revenue_all_time
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2000-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE created_at BETWEEN '2000-01-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', created_at)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2019-12-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_1.metric_time__day BETWEEN '2019-12-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC('month', created_at) AS ds__month
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2019-12-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE created_at BETWEEN '2019-12-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', created_at)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ FROM (
FROM ***************************.fct_bookings bookings_source_src_10001
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_2
) subq_3
) subq_4
Expand Down Expand Up @@ -327,7 +327,7 @@ CROSS JOIN (
FROM ***************************.dim_listings_latest listings_latest_src_10004
) subq_6
) subq_7
WHERE subq_7.metric_time__day BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_8
) subq_9
) subq_10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM (
SELECT
SUM(1) AS bookings
FROM ***************************.fct_bookings bookings_source_src_10001
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2020-01-01'
) subq_17
CROSS JOIN (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -26,5 +26,5 @@ CROSS JOIN (
SELECT
SUM(1) AS listings
FROM ***************************.dim_listings_latest listings_latest_src_10004
WHERE created_at BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE created_at BETWEEN '2020-01-01' AND '2020-01-01'
) subq_23
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ FROM (
) subq_0
) subq_1
) subq_2
WHERE subq_2.metric_time__day BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-02' AS TIMESTAMP)
WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ SELECT
, ds AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_10001
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2020-01-02' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2020-01-02'
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2000-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC('month', created_at) AS ds__month
, SUM(revenue) AS revenue_all_time
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2000-01-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE created_at BETWEEN '2000-01-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', created_at)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ FROM (
FROM ***************************.fct_revenue revenue_src_10006
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN CAST('2019-12-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE subq_1.metric_time__day BETWEEN '2019-12-01' AND '2020-01-01'
) subq_2
) subq_4
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SELECT
DATE_TRUNC('month', created_at) AS ds__month
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10006
WHERE created_at BETWEEN CAST('2019-12-01' AS TIMESTAMP) AND CAST('2020-01-01' AS TIMESTAMP)
WHERE created_at BETWEEN '2019-12-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', created_at)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_12
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
SELECT
subq_6.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_6
WHERE subq_6.ds BETWEEN CAST('2020-01-01' AS TIMESTAMP) AND CAST('2021-01-01' AS TIMESTAMP)
WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01'
) subq_5
INNER JOIN (
-- Compute Metrics via Expressions
Expand Down
Loading