20
20
# software solely pursuant to the terms of the relevant commercial agreement.
21
21
22
22
import sqlalchemy as sa
23
+
23
24
try :
24
25
from sqlalchemy .orm import declarative_base
25
26
except ImportError :
31
32
from unittest import TestCase
32
33
from unittest .mock import patch , MagicMock
33
34
34
-
35
35
fake_cursor = MagicMock (name = 'fake_cursor' )
36
36
FakeCursor = MagicMock (name = 'FakeCursor' , spec = Cursor )
37
37
FakeCursor .return_value = fake_cursor
@@ -77,6 +77,7 @@ class DummyTable(self.Base):
77
77
__tablename__ = 'dummy'
78
78
pk = sa .Column (sa .String , primary_key = True )
79
79
obj_col = sa .Column (Object )
80
+
80
81
self .Base .metadata .create_all (bind = self .engine )
81
82
fake_cursor .execute .assert_called_with (
82
83
('\n CREATE TABLE dummy (\n \t pk STRING NOT NULL, \n \t obj_col OBJECT, '
@@ -91,6 +92,7 @@ class DummyTable(self.Base):
91
92
}
92
93
pk = sa .Column (sa .String , primary_key = True )
93
94
p = sa .Column (sa .String )
95
+
94
96
self .Base .metadata .create_all (bind = self .engine )
95
97
fake_cursor .execute .assert_called_with (
96
98
('\n CREATE TABLE t (\n \t '
@@ -105,6 +107,7 @@ class DummyTable(self.Base):
105
107
__tablename__ = 't'
106
108
ts = sa .Column (sa .BigInteger , primary_key = True )
107
109
p = sa .Column (sa .BigInteger , sa .Computed ("date_trunc('day', ts)" ))
110
+
108
111
self .Base .metadata .create_all (bind = self .engine )
109
112
fake_cursor .execute .assert_called_with (
110
113
('\n CREATE TABLE t (\n \t '
@@ -119,6 +122,7 @@ class DummyTable(self.Base):
119
122
__tablename__ = 't'
120
123
ts = sa .Column (sa .BigInteger , primary_key = True )
121
124
p = sa .Column (sa .BigInteger , sa .Computed ("date_trunc('day', ts)" , persisted = False ))
125
+
122
126
with self .assertRaises (sa .exc .CompileError ):
123
127
self .Base .metadata .create_all (bind = self .engine )
124
128
@@ -131,6 +135,7 @@ class DummyTable(self.Base):
131
135
}
132
136
pk = sa .Column (sa .String , primary_key = True )
133
137
p = sa .Column (sa .String )
138
+
134
139
self .Base .metadata .create_all (bind = self .engine )
135
140
fake_cursor .execute .assert_called_with (
136
141
('\n CREATE TABLE t (\n \t '
@@ -166,6 +171,7 @@ class DummyTable(self.Base):
166
171
}
167
172
pk = sa .Column (sa .String , primary_key = True )
168
173
p = sa .Column (sa .String , primary_key = True )
174
+
169
175
self .Base .metadata .create_all (bind = self .engine )
170
176
fake_cursor .execute .assert_called_with (
171
177
('\n CREATE TABLE t (\n \t '
@@ -207,6 +213,7 @@ def test_column_pk_nullable(self):
207
213
class DummyTable (self .Base ):
208
214
__tablename__ = 't'
209
215
pk = sa .Column (sa .String , primary_key = True , nullable = True )
216
+
210
217
with self .assertRaises (sa .exc .CompileError ):
211
218
self .Base .metadata .create_all (bind = self .engine )
212
219
@@ -230,5 +237,33 @@ class DummyTable(self.Base):
230
237
__tablename__ = 't'
231
238
pk = sa .Column (sa .String , primary_key = True )
232
239
a = sa .Column (Geopoint , crate_index = False )
240
+
241
+ with self .assertRaises (sa .exc .CompileError ):
242
+ self .Base .metadata .create_all (bind = self .engine )
243
+
244
+ def test_text_column_without_columnstore (self ):
245
+ class DummyTable (self .Base ):
246
+ __tablename__ = 't'
247
+ pk = sa .Column (sa .String , primary_key = True )
248
+ a = sa .Column (sa .String , crate_columnstore = False )
249
+ b = sa .Column (sa .String , crate_columnstore = True )
250
+ c = sa .Column (sa .String )
251
+
252
+ self .Base .metadata .create_all (bind = self .engine )
253
+
254
+ fake_cursor .execute .assert_called_with (
255
+ ('\n CREATE TABLE t (\n \t '
256
+ 'pk STRING NOT NULL, \n \t '
257
+ 'a STRING STORAGE WITH (columnstore = false), \n \t '
258
+ 'b STRING, \n \t '
259
+ 'c STRING, \n \t '
260
+ 'PRIMARY KEY (pk)\n )\n \n ' ), ())
261
+
262
+ def test_non_text_column_without_columnstore (self ):
263
+ class DummyTable (self .Base ):
264
+ __tablename__ = 't'
265
+ pk = sa .Column (sa .String , primary_key = True )
266
+ a = sa .Column (sa .Integer , crate_columnstore = False )
267
+
233
268
with self .assertRaises (sa .exc .CompileError ):
234
269
self .Base .metadata .create_all (bind = self .engine )
0 commit comments