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

Dynamic time granularity on any datetime column #181

Merged
merged 2 commits into from Mar 16, 2016
Merged

Conversation

mistercrunch
Copy link
Member

This allows to apply a datetime alteration expression, defined per database.

If your datetime column is a timestamp, you can use this to group by day, week, or whatever.

@gbrian
Copy link
Contributor

gbrian commented Mar 15, 2016

Hi @mistercrunch,

How difficult could be to have the "grain" definition with the datasource definition ?
I mean, can this:
DB_TIME_GRAINS = {

  •        'presto': (
    
  •            Grain('Time Column', '{ds}'),
    
  •            Grain('week', 'date_trunc(week, {ds})'),
    
  •            Grain('month', 'date_trunc(month, {ds})'),
    
  •        ),
    
  •        'mysql': (
    
  •            Grain('Time Column', '{ds}'),
    
  •            Grain('day', 'DATE({ds})'),
    
  •            Grain('week', 'DATE_SUB({ds}, INTERVAL DAYOFWEEK({ds}) - 1 DAY)'),
    
  •            Grain('month', 'DATE_SUB({ds}, INTERVAL DAYOFMONTH({ds}) - 1 DAY)'),
    
  •        ),
    
  •    }
    

be moved as a "Advanced configuration" setting on the datasource form data? In this way will be enough with SQLAlchemy driver to add a new datasource and use this functionality.

Just to confirm, same functionality can be achieve by using expression fields, right ? ofc this way is better! ;)

Any chance to use SQLAlchemy functions ?
http://stackoverflow.com/questions/12019766/how-to-get-month-and-year-from-date-field-in-sqlalchemy
http://stackoverflow.com/questions/1453591/how-to-filter-query-in-sqlalchemy-by-year-datetime-column

Thanks

@mistercrunch
Copy link
Member Author

At the datasource level it would have to be defined for each datasource, which is redundant, though maybe the datasource could eventually offer a whitelist/blacklist configuration.

From my understanding I don't think SqlAlchemy functions are reliable or have any guarantees that they work across dialects...

@mistercrunch mistercrunch force-pushed the time_grain branch 8 times, most recently from 949bfee to c619366 Compare March 16, 2016 19:32
@landscape-bot
Copy link

Code Health
Repository health decreased by 4% when pulling a162d11 on time_grain into 2aa0e0d on master.

@landscape-bot
Copy link

Code Health
Repository health increased by 3% when pulling 27fb810 on time_grain into 2aa0e0d on master.

@landscape-bot
Copy link

Code Health
Repository health increased by 4% when pulling b321efc on time_grain into 2aa0e0d on master.

@landscape-bot
Copy link

Code Health
Repository health increased by 0.52% when pulling 61ab06d on time_grain into 2aa0e0d on master.

mistercrunch added a commit that referenced this pull request Mar 16, 2016
Dynamic time granularity on any datetime column
@mistercrunch mistercrunch merged commit ae1e66f into master Mar 16, 2016
@mistercrunch mistercrunch deleted the time_grain branch March 16, 2016 23:11
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.8.1 labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.8.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants