superset icon indicating copy to clipboard operation
superset copied to clipboard

Apply time filtering to "time grain" truncated dates

Open nbonnotte opened this issue 9 years ago • 3 comments

  • [x] I have reproduced the issue with at least the latest released version of superset
  • [x] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

v0.19.1

Expected results

Say I want to display the number of items purchased per week over the last 3 months with a bar chart. I choose a weekly time grain, and set the time window to start from "90 days ago"

image

I would expect the first bar, for the first week, to correspond to the number of items purchased for the whole week, not for the part of that week that happen to be within the 90-day time range.

SELECT DATE_TRUNC('week', purchase_timestamp) AS __timestamp,
       COUNT(*) AS purchases
FROM purchase_table
WHERE DATE_TRUNC('week', purchase_timestamp) >= DATE_TRUNC('week', TIMESTAMP '2017-06-29 00:00:00')
  AND DATE_TRUNC('week', purchase_timestamp) <= DATE_TRUNC('week', TIMESTAMP '2017-09-26 00:00:00')
GROUP BY DATE_TRUNC('week', purchase_timestamp)

Actual results

The first bar is truncated, and does not correspond to the whole week

SELECT DATE_TRUNC('week', purchase_timestamp) AS __timestamp,
       COUNT(*) AS purchases
FROM purchase_table
WHERE purchase_timestamp >= '2017-06-29 00:00:00'
  AND purchase_timestamp <= '2017-09-26 00:00:00'
GROUP BY DATE_TRUNC('week', purchase_timestamp)

nbonnotte avatar Sep 27 '17 10:09 nbonnotte

I agreed that this is the desired behavior to get "full buckets"

mistercrunch avatar Sep 27 '17 16:09 mistercrunch

I also found an issue with literal_column from SQLAlchemy that will escape the "%" symbol in the string. The final SQL will have two consecutive "%". screen shot 2017-12-22 at 8 00 51 pm

This issue is related to #617 . I tried to switch to the SQLAlchemy 1.2.0b3 and it works fine. So they already fix this issue in the latest version.

nwang57 avatar Dec 23 '17 01:12 nwang57

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Apr 11 '19 04:04 stale[bot]