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

Snowflake: add support for regions and enable by default #3550

Merged
merged 2 commits into from
Mar 7, 2019
Merged
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
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