@@ -56,7 +56,8 @@ public function testCreateNewTableSQL()
56
56
$ newTable ->setPrimaryKey (['id ' ]);
57
57
58
58
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
59
- $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String, oneVal Float64, twoVal String, flag UInt8, mask Int16, hash FixedString(32)) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " , implode ('; ' , $ migrationSQLs ));
59
+ $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String, oneVal Float64, twoVal String, flag UInt8, mask Int16, hash FixedString(32)) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " ,
60
+ implode ('; ' , $ migrationSQLs ));
60
61
foreach ($ migrationSQLs as $ sql ) {
61
62
$ this ->connection ->exec ($ sql );
62
63
}
@@ -102,7 +103,8 @@ public function testIndexGranularityOption()
102
103
103
104
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
104
105
$ generatedSQL = implode ('; ' , $ migrationSQLs );
105
- $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(EventDate, (id), 4096) " , $ generatedSQL );
106
+ $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(EventDate, (id), 4096) " ,
107
+ $ generatedSQL );
106
108
foreach ($ migrationSQLs as $ sql ) {
107
109
$ this ->connection ->exec ($ sql );
108
110
}
@@ -123,7 +125,8 @@ public function testEngineMergeOption()
123
125
124
126
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
125
127
$ generatedSQL = implode ('; ' , $ migrationSQLs );
126
- $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String) ENGINE = MergeTree(EventDate, (id), 8192) " , $ generatedSQL );
128
+ $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT today(), id UInt32, payload String) ENGINE = MergeTree(EventDate, (id), 8192) " ,
129
+ $ generatedSQL );
127
130
foreach ($ migrationSQLs as $ sql ) {
128
131
$ this ->connection ->exec ($ sql );
129
132
}
@@ -166,7 +169,8 @@ public function testEventDateColumnOption()
166
169
167
170
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
168
171
$ generatedSQL = implode ('; ' , $ migrationSQLs );
169
- $ this ->assertEquals ("CREATE TABLE test_table (event_date Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(event_date, (id), 8192) " , $ generatedSQL );
172
+ $ this ->assertEquals ("CREATE TABLE test_table (event_date Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(event_date, (id), 8192) " ,
173
+ $ generatedSQL );
170
174
foreach ($ migrationSQLs as $ sql ) {
171
175
$ this ->connection ->exec ($ sql );
172
176
}
@@ -189,7 +193,8 @@ public function testEventDateColumnBadOption()
189
193
$ this ->expectException (\Exception::class);
190
194
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
191
195
$ generatedSQL = implode ('; ' , $ migrationSQLs );
192
- $ this ->assertEquals ("CREATE TABLE test_table (event_date Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(event_date, (id), 8192) " , $ generatedSQL );
196
+ $ this ->assertEquals ("CREATE TABLE test_table (event_date Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(event_date, (id), 8192) " ,
197
+ $ generatedSQL );
193
198
foreach ($ migrationSQLs as $ sql ) {
194
199
$ this ->connection ->exec ($ sql );
195
200
}
@@ -211,7 +216,8 @@ public function testEventDateProviderColumnOption()
211
216
212
217
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
213
218
$ generatedSQL = implode ('; ' , $ migrationSQLs );
214
- $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT toDate(updated_at), id UInt32, payload String, updated_at DateTime) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " , $ generatedSQL );
219
+ $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT toDate(updated_at), id UInt32, payload String, updated_at DateTime) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " ,
220
+ $ generatedSQL );
215
221
foreach ($ migrationSQLs as $ sql ) {
216
222
$ this ->connection ->exec ($ sql );
217
223
}
@@ -234,7 +240,8 @@ public function testEventDateProviderColumnBadOption()
234
240
$ this ->expectException (\Exception::class);
235
241
$ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
236
242
$ generatedSQL = implode ('; ' , $ migrationSQLs );
237
- $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT toDate(updated_at), id UInt32, payload String, updated_at DateTime) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " , $ generatedSQL );
243
+ $ this ->assertEquals ("CREATE TABLE test_table (EventDate Date DEFAULT toDate(updated_at), id UInt32, payload String, updated_at DateTime) ENGINE = ReplacingMergeTree(EventDate, (id), 8192) " ,
244
+ $ generatedSQL );
238
245
foreach ($ migrationSQLs as $ sql ) {
239
246
$ this ->connection ->exec ($ sql );
240
247
}
@@ -262,7 +269,7 @@ public function testListTableIndexes()
262
269
263
270
$ this ->assertEquals (1 , \count ($ indexes ));
264
271
265
- if ($ index = current ($ indexes )) {
272
+ if ($ index = current ($ indexes )) {
266
273
$ this ->assertInstanceOf (Index::class, $ index );
267
274
268
275
$ this ->assertEquals (['id ' , 'event_date ' ], $ index ->getColumns ());
@@ -272,6 +279,41 @@ public function testListTableIndexes()
272
279
$ this ->connection ->exec ('DROP TABLE test_indexes_table ' );
273
280
}
274
281
282
+ public function testTableWithSamplingExpression ()
283
+ {
284
+ $ fromSchema = $ this ->connection ->getSchemaManager ()->createSchema ();
285
+ $ toSchema = clone $ fromSchema ;
286
+
287
+ $ newTable = $ toSchema ->createTable ('test_sampling_table ' );
288
+
289
+ $ newTable ->addColumn ('id ' , 'integer ' , ['unsigned ' => true ]);
290
+ $ newTable ->addColumn ('payload ' , 'string ' );
291
+ $ newTable ->addColumn ('event_date ' , Type::DATE );
292
+ $ newTable ->addOption ('eventDateColumn ' , 'event_date ' );
293
+ $ newTable ->addOption ('samplingExpression ' , 'intHash32(id) ' );
294
+ $ newTable ->setPrimaryKey (['id ' , 'event_date ' ]);
295
+ $ migrationSQLs = $ fromSchema ->getMigrateToSql ($ toSchema , $ this ->connection ->getDatabasePlatform ());
296
+ $ generatedSQL = implode ('; ' , $ migrationSQLs );
297
+ $ this ->assertEquals ("CREATE TABLE test_sampling_table (event_date Date DEFAULT today(), id UInt32, payload String) ENGINE = ReplacingMergeTree(event_date, intHash32(id), (id, event_date, intHash32(id)), 8192) " ,
298
+ $ generatedSQL );
299
+ foreach ($ migrationSQLs as $ sql ) {
300
+ $ this ->connection ->exec ($ sql );
301
+ }
302
+
303
+ $ indexes = $ this ->connection ->getSchemaManager ()->listTableIndexes ('test_sampling_table ' );
304
+
305
+ $ this ->assertEquals (1 , \count ($ indexes ));
306
+
307
+ if ($ index = current ($ indexes )) {
308
+ $ this ->assertInstanceOf (Index::class, $ index );
309
+
310
+ $ this ->assertEquals (['id ' , 'event_date ' ], $ index ->getColumns ());
311
+ $ this ->assertTrue ($ index ->isPrimary ());
312
+ }
313
+
314
+ $ this ->connection ->exec ('DROP TABLE test_sampling_table ' );
315
+ }
316
+
275
317
public function testNullableColumns ()
276
318
{
277
319
$ fromSchema = $ this ->connection ->getSchemaManager ()->createSchema ();
0 commit comments