Skip to content

Commit

Permalink
Implement Snowflake engine with supported time grains (apache#4882)
Browse files Browse the repository at this point in the history
* Implement Snowflake engine with supported time grains

* Fix typo in second grain
  • Loading branch information
villebro authored and michellethomas committed May 23, 2018
1 parent 6ef8b78 commit 357b1d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ Here's a list of some of the recommended packages.
+---------------+-------------------------------------+-------------------------------------------------+
| sqlite | | ``sqlite://`` |
+---------------+-------------------------------------+-------------------------------------------------+
| Snowflake | ``pip install snowflake-sqlalchemy``| ``snowflake://`` |
+---------------+-------------------------------------+-------------------------------------------------+
| Redshift | ``pip install sqlalchemy-redshift`` | ``redshift+psycopg2://`` |
+---------------+-------------------------------------+-------------------------------------------------+
| MSSQL | ``pip install pymssql`` | ``mssql://`` |
Expand Down
16 changes: 16 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ def get_table_names(cls, schema, inspector):
return sorted(tables)


class SnowflakeEngineSpec(PostgresBaseEngineSpec):
engine = 'snowflake'

time_grains = (
Grain('Time Column', _('Time Column'), '{col}', None),
Grain('second', _('second'), "DATE_TRUNC('SECOND', {col})", 'PT1S'),
Grain('minute', _('minute'), "DATE_TRUNC('MINUTE', {col})", 'PT1M'),
Grain('hour', _('hour'), "DATE_TRUNC('HOUR', {col})", 'PT1H'),
Grain('day', _('day'), "DATE_TRUNC('DAY', {col})", 'P1D'),
Grain('week', _('week'), "DATE_TRUNC('WEEK', {col})", 'P1W'),
Grain('month', _('month'), "DATE_TRUNC('MONTH', {col})", 'P1M'),
Grain('quarter', _('quarter'), "DATE_TRUNC('QUARTER', {col})", 'P0.25Y'),
Grain('year', _('year'), "DATE_TRUNC('YEAR', {col})", 'P1Y'),
)


class VerticaEngineSpec(PostgresBaseEngineSpec):
engine = 'vertica'

Expand Down

0 comments on commit 357b1d8

Please sign in to comment.