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

I want to specify custom time grain #15037

Closed
EBoisseauSierra opened this issue Jun 8, 2021 · 4 comments
Closed

I want to specify custom time grain #15037

EBoisseauSierra opened this issue Jun 8, 2021 · 4 comments
Labels
enhancement:request Enhancement request submitted by anyone from the community explore:control Related to the controls panel of Explore

Comments

@EBoisseauSierra
Copy link
Contributor

Issue

I would like to aggregate my time-series charts on custom time grains. Currently only “1 unit” grains are available: 1s, 1min, 1h, 1 day, etc.

Yet I would like to be able to aggregate by, e.g., 5-minute, 15-minute, 6-hour time buckets.

Requested feature

I want to be able to define custom time grains.

This could happen either:

  • as a Superset instance specific variable (i.e. defining new time grains in superset_config.py): this has the advantage of ensuring that only admin specify time grains (greater chance for the definition to be correct and less burden on users) and enable it for any user in the already existing dropdown.
  • in the Explore panel:
    • let the user specify a “magic string” (e.g. 15T, 6H, etc. : easiest to implement, greatest flexibility, yet risk of parsing garbage)
    • build a GUI for it (number input to specify 5, 6, or 15 + dropdown menu to select the unit minute, hour, etc.)

Alternative

None that I'm aware of.

Additional info

We'd like to have these time grains available to pandas.resample advanced feature as well.

@junlincc junlincc added the enhancement:request Enhancement request submitted by anyone from the community label Jun 8, 2021
@junlincc
Copy link
Member

junlincc commented Jun 8, 2021

@EBoisseauSierra thanks for the request. i like the idea we have been thinking about blending all time controls including time grain into one time range popover, eventually remove the concepts of time, and have it be a part of regular filter in Explore. this will be the next long tail project which requires lots of planning and design. lmk if your team is interested in collaborating cc @zhaoyongjie

@junlincc junlincc added the explore:control Related to the controls panel of Explore label Jun 8, 2021
@EBoisseauSierra
Copy link
Contributor Author

EBoisseauSierra commented Jun 21, 2021

Actually, this is already possible via the TIME_GRAIN_ADDONS and TIME_GRAIN_ADDON_EXPRESSIONS variables in config.py, thanks to @villebro!

@lelelethu
Copy link

Actually, this is already possible via the TIME_GRAIN_ADDONS and TIME_GRAIN_ADDON_EXPRESSIONS variables in config.py, thanks to @villebro!

When i using that but not working.
This my code in config.py:
TIME_GRAIN_ADDONS = {
'PT2S': '2 second',
"PT6H": "6 hours",
"PT15M": "15 minutes",
}

TIME_GRAIN_ADDON_EXPRESSIONS = {
'postgresql': {
'PT2S': 'toDateTime(intDiv(toUInt32(toDateTime({col})), 2)*2)',
'PT6H': "date_trunc('day', {col}) + date_trunc('hour', {col})::int / 6 * interval '6 h'",
'PT15M': "date_trunc('hour', {col}) + date_part('minute', {col})::int / 15 * interval '15 min'",
}
}

What am I wrong?

@janajay
Copy link

janajay commented Mar 27, 2024

@lelelethu you need to use this in file superset_config.py it will get reflect
TIME_GRAIN_ADDONS = {"PT2S": "2 second"}

TIME_GRAIN_ADDON_EXPRESSIONS = {
"clickhouse": {
"PT2S": "toDateTime(intDiv(toUInt32(toDateTime({col})), 2)*2)",
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement:request Enhancement request submitted by anyone from the community explore:control Related to the controls panel of Explore
Projects
No open projects
Development

No branches or pull requests

4 participants