From fa3da8c888e25b62e72faaab8987631f07096b56 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Thu, 26 Apr 2018 00:44:24 +0300 Subject: [PATCH] Implement Snowflake engine with supported time grains (#4882) * Implement Snowflake engine with supported time grains * Fix typo in second grain --- docs/installation.rst | 2 ++ superset/db_engine_specs.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/installation.rst b/docs/installation.rst index be4abe8168b30..ca9cf3f595815 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -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://`` | diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 0c7444c3f03ec..49dd39cd6d4aa 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -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'