mtsql 1.11.19__py3-none-any.whl → 1.11.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mt/sql/redshift/__init__.py +1 -17
- mt/sql/redshift/commands.py +348 -261
- mt/sql/redshift/ddl.py +29 -27
- mt/sql/redshift/dialect.py +457 -345
- mt/sql/version.py +1 -1
- {mtsql-1.11.19.dist-info → mtsql-1.11.20.dist-info}/METADATA +2 -1
- mtsql-1.11.20.dist-info/RECORD +17 -0
- mtsql-1.11.19.dist-info/RECORD +0 -17
- {mtsql-1.11.19.dist-info → mtsql-1.11.20.dist-info}/LICENSE +0 -0
- {mtsql-1.11.19.dist-info → mtsql-1.11.20.dist-info}/WHEEL +0 -0
- {mtsql-1.11.19.dist-info → mtsql-1.11.20.dist-info}/top_level.txt +0 -0
mt/sql/redshift/ddl.py
CHANGED
|
@@ -7,11 +7,9 @@ def _check_if_key_exists(key):
|
|
|
7
7
|
return isinstance(key, sa.Column) or key
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def get_table_attributes(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sortkey=None,
|
|
14
|
-
interleaved_sortkey=None):
|
|
10
|
+
def get_table_attributes(
|
|
11
|
+
preparer, diststyle=None, distkey=None, sortkey=None, interleaved_sortkey=None
|
|
12
|
+
):
|
|
15
13
|
"""
|
|
16
14
|
Parse the table attributes into an acceptable string for Redshift,
|
|
17
15
|
checking for valid combinations of distribution options.
|
|
@@ -56,17 +54,15 @@ def get_table_attributes(preparer,
|
|
|
56
54
|
has_distkey = _check_if_key_exists(distkey)
|
|
57
55
|
if diststyle:
|
|
58
56
|
diststyle = diststyle.upper()
|
|
59
|
-
if diststyle not in (
|
|
57
|
+
if diststyle not in ("EVEN", "KEY", "ALL"):
|
|
58
|
+
raise sa.exc.ArgumentError("diststyle {0} is invalid".format(diststyle))
|
|
59
|
+
if diststyle != "KEY" and has_distkey:
|
|
60
60
|
raise sa.exc.ArgumentError(
|
|
61
|
-
|
|
61
|
+
"DISTSTYLE EVEN/ALL is not compatible with a DISTKEY."
|
|
62
62
|
)
|
|
63
|
-
if diststyle
|
|
63
|
+
if diststyle == "KEY" and not has_distkey:
|
|
64
64
|
raise sa.exc.ArgumentError(
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
if diststyle == 'KEY' and not has_distkey:
|
|
68
|
-
raise sa.exc.ArgumentError(
|
|
69
|
-
u"DISTKEY specification is required for DISTSTYLE KEY"
|
|
65
|
+
"DISTKEY specification is required for DISTSTYLE KEY"
|
|
70
66
|
)
|
|
71
67
|
text += " DISTSTYLE " + diststyle
|
|
72
68
|
|
|
@@ -87,12 +83,10 @@ def get_table_attributes(preparer,
|
|
|
87
83
|
keys = sortkey if has_sortkey else interleaved_sortkey
|
|
88
84
|
if isinstance(keys, (str, sa.Column)):
|
|
89
85
|
keys = [keys]
|
|
90
|
-
keys = [key.name if isinstance(key, sa.Column) else key
|
|
91
|
-
for key in keys]
|
|
86
|
+
keys = [key.name if isinstance(key, sa.Column) else key for key in keys]
|
|
92
87
|
if has_interleaved:
|
|
93
88
|
text += " INTERLEAVED"
|
|
94
|
-
sortkey_string = ", ".join(preparer.quote(key)
|
|
95
|
-
for key in keys)
|
|
89
|
+
sortkey_string = ", ".join(preparer.quote(key) for key in keys)
|
|
96
90
|
text += " SORTKEY ({0})".format(sortkey_string)
|
|
97
91
|
return text
|
|
98
92
|
|
|
@@ -108,7 +102,7 @@ class CreateMaterializedView(DDLElement):
|
|
|
108
102
|
|
|
109
103
|
>>> import sqlalchemy as sa
|
|
110
104
|
>>> from sqlalchemy_redshift.dialect import CreateMaterializedView
|
|
111
|
-
>>> engine = sa.create_engine('
|
|
105
|
+
>>> engine = sa.create_engine('mtsql_redshift://example')
|
|
112
106
|
>>> metadata = sa.MetaData()
|
|
113
107
|
>>> user = sa.Table(
|
|
114
108
|
... 'user',
|
|
@@ -138,8 +132,17 @@ class CreateMaterializedView(DDLElement):
|
|
|
138
132
|
The CreateMaterializedView is a DDLElement, so it can be executed via any
|
|
139
133
|
execute() command, be it from an Engine, Session, or Connection.
|
|
140
134
|
"""
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
|
|
136
|
+
def __init__(
|
|
137
|
+
self,
|
|
138
|
+
name,
|
|
139
|
+
selectable,
|
|
140
|
+
backup=True,
|
|
141
|
+
diststyle=None,
|
|
142
|
+
distkey=None,
|
|
143
|
+
sortkey=None,
|
|
144
|
+
interleaved_sortkey=None,
|
|
145
|
+
):
|
|
143
146
|
"""
|
|
144
147
|
Parameters
|
|
145
148
|
----------
|
|
@@ -190,21 +193,19 @@ def compile_create_materialized_view(element, compiler, **kw):
|
|
|
190
193
|
diststyle=element.diststyle,
|
|
191
194
|
distkey=element.distkey,
|
|
192
195
|
sortkey=element.sortkey,
|
|
193
|
-
interleaved_sortkey=element.interleaved_sortkey
|
|
196
|
+
interleaved_sortkey=element.interleaved_sortkey,
|
|
194
197
|
)
|
|
195
198
|
# Defaults to yes, so omit default cas3
|
|
196
199
|
backup = "" if element.backup else "BACKUP NO "
|
|
197
|
-
selectable = compiler.sql_compiler.process(element.selectable,
|
|
198
|
-
literal_binds=True)
|
|
200
|
+
selectable = compiler.sql_compiler.process(element.selectable, literal_binds=True)
|
|
199
201
|
text = text.format(
|
|
200
202
|
name=element.name,
|
|
201
203
|
backup=backup,
|
|
202
204
|
table_attributes=table_attributes,
|
|
203
|
-
selectable=selectable
|
|
205
|
+
selectable=selectable,
|
|
204
206
|
)
|
|
205
207
|
# Clean it up to have no leading spaces
|
|
206
|
-
text = "\n".join([line.strip() for line in text.split("\n")
|
|
207
|
-
if line.strip()])
|
|
208
|
+
text = "\n".join([line.strip() for line in text.split("\n") if line.strip()])
|
|
208
209
|
return text
|
|
209
210
|
|
|
210
211
|
|
|
@@ -218,7 +219,7 @@ class DropMaterializedView(DDLElement):
|
|
|
218
219
|
|
|
219
220
|
>>> import sqlalchemy as sa
|
|
220
221
|
>>> from sqlalchemy_redshift.dialect import DropMaterializedView
|
|
221
|
-
>>> engine = sa.create_engine('
|
|
222
|
+
>>> engine = sa.create_engine('mtsql_redshift://example')
|
|
222
223
|
>>> drop = DropMaterializedView(
|
|
223
224
|
... 'materialized_view_of_users',
|
|
224
225
|
... if_exists=True
|
|
@@ -231,6 +232,7 @@ class DropMaterializedView(DDLElement):
|
|
|
231
232
|
|
|
232
233
|
This can be included in any execute() statement.
|
|
233
234
|
"""
|
|
235
|
+
|
|
234
236
|
def __init__(self, name, if_exists=False, cascade=False):
|
|
235
237
|
"""
|
|
236
238
|
Build the DropMaterializedView DDLElement.
|