|
1 | 1 | try:
|
2 | 2 | import snowflake.connector
|
| 3 | + |
3 | 4 | enabled = True
|
4 | 5 | except ImportError:
|
5 | 6 | enabled = False
|
@@ -39,14 +40,27 @@ def configuration_schema(cls):
|
39 | 40 | "type": "object",
|
40 | 41 | "properties": {
|
41 | 42 | "account": {"type": "string"},
|
42 |
| - "region": {"type": "string", "default": "us-west"}, |
43 | 43 | "user": {"type": "string"},
|
44 | 44 | "password": {"type": "string"},
|
45 | 45 | "warehouse": {"type": "string"},
|
46 | 46 | "database": {"type": "string"},
|
| 47 | + "region": {"type": "string", "default": "us-west"}, |
| 48 | + "lower_case_columns": { |
| 49 | + "type": "boolean", |
| 50 | + "title": "Lower Case Column Names in Results", |
| 51 | + "default": False, |
| 52 | + }, |
47 | 53 | "host": {"type": "string"},
|
48 | 54 | },
|
49 |
| - "order": ["account", "region", "user", "password", "warehouse", "database", "host"], |
| 55 | + "order": [ |
| 56 | + "account", |
| 57 | + "user", |
| 58 | + "password", |
| 59 | + "warehouse", |
| 60 | + "database", |
| 61 | + "region", |
| 62 | + "host", |
| 63 | + ], |
50 | 64 | "required": ["user", "password", "account", "database", "warehouse"],
|
51 | 65 | "secret": ["password"],
|
52 | 66 | "extra_options": [
|
@@ -81,20 +95,28 @@ def _get_connection(self):
|
81 | 95 | else:
|
82 | 96 | host = "{}.snowflakecomputing.com".format(account)
|
83 | 97 |
|
84 |
| - |
85 | 98 | connection = snowflake.connector.connect(
|
86 |
| - user = self.configuration["user"], |
87 |
| - password = self.configuration["password"], |
88 |
| - account = account, |
89 |
| - region = region, |
90 |
| - host = host |
| 99 | + user=self.configuration["user"], |
| 100 | + password=self.configuration["password"], |
| 101 | + account=account, |
| 102 | + region=region, |
| 103 | + host=host, |
91 | 104 | )
|
92 | 105 |
|
93 | 106 | return connection
|
94 | 107 |
|
| 108 | + def _column_name(self, column_name): |
| 109 | + if self.configuration.get("lower_case_columns", False): |
| 110 | + return column_name.lower() |
| 111 | + |
| 112 | + return column_name |
| 113 | + |
95 | 114 | def _parse_results(self, cursor):
|
96 | 115 | columns = self.fetch_columns(
|
97 |
| - [(i[0], self.determine_type(i[1], i[5])) for i in cursor.description] |
| 116 | + [ |
| 117 | + (self._column_name(i[0]), self.determine_type(i[1], i[5])) |
| 118 | + for i in cursor.description |
| 119 | + ] |
98 | 120 | )
|
99 | 121 | rows = [
|
100 | 122 | dict(zip((column["name"] for column in columns), row)) for row in cursor
|
@@ -137,10 +159,10 @@ def _run_query_without_warehouse(self, query):
|
137 | 159 | cursor.close()
|
138 | 160 | connection.close()
|
139 | 161 |
|
140 |
| - return data, error |
141 |
| - |
| 162 | + return data, error |
| 163 | + |
142 | 164 | def _database_name_includes_schema(self):
|
143 |
| - return '.' in self.configuration.get('database') |
| 165 | + return "." in self.configuration.get("database") |
144 | 166 |
|
145 | 167 | def get_schema(self, get_stats=False):
|
146 | 168 | if self._database_name_includes_schema():
|
|
0 commit comments