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

Time grain config #1188

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 19 additions & 0 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ class CeleryConfig(object):
# Timeout duration for SQL Lab synchronous queries
SQLLAB_TIMEOUT = 30

# ---------------------------------------------------
# Configure Caravel to use a custom Time Grain for Databases
# ---------------------------------------------------

# DB_CUSTOM_GRAIN = (
# ('postgresql', (
# ("Time Column", 'Time Column', "{col}"),
# ("second", 'second', "DATE_TRUNC('second', {col})"),
# ("minute", 'minute', "DATE_TRUNC('minute', {col})"),
# ("hour", 'hour', "DATE_TRUNC('hour', {col})"),
# ("day", 'day', "DATE_TRUNC('day', {col})"),
# ("week", 'week', "DATE({col}) - DAYOFWEEK(DATE({col})) + 1"),
# ("month", 'month', "DATE_TRUNC('month', {col})"),
# ("year", 'year', "DATE_TRUNC('year', {col})"),
# )),
# )

DB_CUSTOM_GRAIN = None

try:
from caravel_config import * # noqa
except ImportError:
Expand Down
7 changes: 7 additions & 0 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ def grains(self):
}
db_time_grains['redshift'] = db_time_grains['postgresql']
db_time_grains['vertica'] = db_time_grains['postgresql']
custom_grain = config.get('DB_CUSTOM_GRAIN')
if custom_grain:
for db, grains in custom_grain:
db_time_grains[db] = tuple(
Grain(name, label, function)
for name, label, function in grains)

for db_type, grains in db_time_grains.items():
if self.sqlalchemy_uri.startswith(db_type):
return grains
Expand Down