Skip to content

Commit

Permalink
Snowflake: add support for regions and enable by default (#3550)
Browse files Browse the repository at this point in the history
* Bring back Snowflake from its exile.

* Snowflake: add support for regions.
  • Loading branch information
arikfr authored Mar 7, 2019
1 parent 8737e80 commit 61f143d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
22 changes: 19 additions & 3 deletions redash/query_runner/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ def configuration_schema(cls):
},
"database": {
"type": "string"
},
"region": {
"type": "string",
"default": "us-west"
}
},
"order": ["account", "user", "password", "warehouse", "database", "region"],
"required": ["user", "password", "account", "database", "warehouse"],
"secret": ["password"]
}
Expand All @@ -56,22 +61,32 @@ def enabled(cls):
return enabled

def run_query(self, query, user):
region = self.configuration.get('region')

# for us-west we don't need to pass a region (and if we do, it fails to connect)
if region == 'us-west':
region = None

connection = snowflake.connector.connect(
user=self.configuration['user'],
password=self.configuration['password'],
account=self.configuration['account'],
region=region
)

cursor = connection.cursor()

try:
cursor.execute("USE WAREHOUSE {}".format(self.configuration['warehouse']))
cursor.execute("USE WAREHOUSE {}".format(
self.configuration['warehouse']))
cursor.execute("USE {}".format(self.configuration['database']))

cursor.execute(query)

columns = self.fetch_columns([(i[0], TYPES_MAP.get(i[1], None)) for i in cursor.description])
rows = [dict(zip((c['name'] for c in columns), row)) for row in cursor]
columns = self.fetch_columns(
[(i[0], TYPES_MAP.get(i[1], None)) for i in cursor.description])
rows = [dict(zip((c['name'] for c in columns), row))
for row in cursor]

data = {'columns': columns, 'rows': rows}
error = None
Expand Down Expand Up @@ -109,4 +124,5 @@ def get_schema(self, get_stats=False):

return schema.values()


register(Snowflake)
1 change: 1 addition & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def all_settings():
'redash.query_runner.kylin',
'redash.query_runner.drill',
'redash.query_runner.uptycs',
'redash.query_runner.snowflake',
]

enabled_query_runners = array_from_string(os.environ.get("REDASH_ENABLED_QUERY_RUNNERS", ",".join(default_query_runners)))
Expand Down
5 changes: 1 addition & 4 deletions requirements_all_ds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ qds-sdk>=1.9.6
ibm-db>=2.0.9
pydruid==0.4
requests_aws_sign==0.1.4
snowflake_connector_python==1.6.10
# certifi is needed to support MongoDB and SSL:
certifi
# We don't install snowflake connector by default, as it's causing conflicts with
# other packages. To properly support it we probably need to switch from pyOpenSSL
# to the other package snowflake is using (that's compatible with it).
# snowflake_connector_python==1.6.10

0 comments on commit 61f143d

Please sign in to comment.