1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
4
|
|
|
* license agreements. See the NOTICE file distributed with this work for |
5
|
|
|
* additional information regarding copyright ownership. Crate licenses |
6
|
|
|
* this file to you under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. You may |
8
|
|
|
* obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations |
16
|
|
|
* under the License. |
17
|
|
|
* |
18
|
|
|
* However, if you have executed another commercial license agreement |
19
|
|
|
* with Crate these terms will supersede the license and you may use the |
20
|
|
|
* software solely pursuant to the terms of the relevant commercial agreement. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Crate\Test\DBAL\Functional; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
use Crate\DBAL\Platforms\CratePlatform; |
27
|
|
|
use Crate\Test\DBAL\DBALFunctionalTestCase; |
28
|
|
|
use Doctrine\DBAL\DBALException; |
29
|
|
|
use Doctrine\DBAL\Schema\Table; |
30
|
|
|
use InvalidArgumentException; |
31
|
|
|
|
32
|
|
|
class TableOptionsTest extends DBALFunctionalTestCase { |
33
|
|
|
|
34
|
|
|
public function tearDown() : void |
35
|
|
|
{ |
36
|
|
|
parent::tearDown(); |
37
|
|
|
if ($this->_conn->getSchemaManager()->tablesExist("ddc1372_foobar")) { |
38
|
|
|
try { |
39
|
|
|
$sm = $this->_conn->getSchemaManager(); |
40
|
|
|
$sm->dropTable('table_option_test'); |
41
|
|
|
} catch(\Exception $e) { |
42
|
|
|
$this->fail($e->getMessage()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testAdditionalTableOptions() |
48
|
|
|
{ |
49
|
|
|
$platform = $this->_conn->getDatabasePlatform(); |
50
|
|
|
|
51
|
|
|
$options = []; |
52
|
|
|
$options['sharding_routing_column'] = 'id'; |
53
|
|
|
$options['sharding_num_shards'] = 6; |
54
|
|
|
$options['partition_columns'] = ['parted', 'date']; |
55
|
|
|
$options['table_options'] = []; |
56
|
|
|
$options['table_options']['number_of_replicas'] = '0-2'; |
57
|
|
|
$options['table_options']['write.wait_for_active_shards'] = 'ALL'; |
58
|
|
|
|
59
|
|
|
$table = new Table('t1', [], [], [], 0, $options); |
60
|
|
|
$table->addColumn('id', 'integer'); |
61
|
|
|
$table->addColumn('parted', 'integer'); |
62
|
|
|
$table->addColumn('date', 'timestamp'); |
63
|
|
|
|
64
|
|
|
$sql = $platform->getCreateTableSQL($table); |
65
|
|
|
$this->assertEquals(array( |
66
|
|
|
'CREATE TABLE t1 (id INTEGER, parted INTEGER, date TIMESTAMP)' |
67
|
|
|
. ' CLUSTERED BY (id) INTO 6 SHARDS' |
68
|
|
|
. ' PARTITIONED BY (parted, date)' |
69
|
|
|
. ' WITH ("number_of_replicas" = \'0-2\', "write.wait_for_active_shards" = \'ALL\')') |
70
|
|
|
, $sql); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGetAdditionalTableOptions() |
74
|
|
|
{ |
75
|
|
|
$options = []; |
76
|
|
|
$options['sharding_routing_column'] = 'id'; |
77
|
|
|
$options['sharding_num_shards'] = 6; |
78
|
|
|
$options['partition_columns'] = ['parted', 'date']; |
79
|
|
|
$options['table_options'] = []; |
80
|
|
|
$options['table_options']['number_of_replicas'] = '0-2'; |
81
|
|
|
$options['table_options']['write.wait_for_active_shards'] = 'ALL'; |
82
|
|
|
|
83
|
|
|
$table = new Table('table_option_test', [], [], [], 0, $options); |
84
|
|
|
$table->addColumn('id', 'integer'); |
85
|
|
|
$table->addColumn('parted', 'integer'); |
86
|
|
|
$table->addColumn('date', 'timestamp'); |
87
|
|
|
|
88
|
|
|
$sm = $this->_conn->getSchemaManager(); |
89
|
|
|
$sm->createTable($table); |
90
|
|
|
|
91
|
|
|
$schema = $sm->createSchema(); |
92
|
|
|
|
93
|
|
|
$retrievedTable = $schema->getTable($table->getName()); |
94
|
|
|
$options = $retrievedTable->getOptions(); |
95
|
|
|
|
96
|
|
|
$this->assertEquals($options['sharding_routing_column'], 'id'); |
97
|
|
|
$this->assertEquals($options['sharding_num_shards'], 6); |
98
|
|
|
$this->assertEquals($options['partition_columns'], ['parted', 'date']); |
99
|
|
|
$this->assertEquals($options['table_options']['number_of_replicas'], '0-2'); |
100
|
|
|
$this->assertEquals($options['table_options']['write.wait_for_active_shards'], 'ALL'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testPartitionColumnsNotArray() |
104
|
|
|
{ |
105
|
|
|
$platform = $this->_conn->getDatabasePlatform(); |
106
|
|
|
|
107
|
|
|
$options = []; |
108
|
|
|
$options['partition_columns'] = 'parted'; |
109
|
|
|
$table = new Table('t1', [], [], [], 0, $options); |
110
|
|
|
$table->addColumn('parted', 'integer'); |
111
|
|
|
|
112
|
|
|
$this->expectException(InvalidArgumentException::class); |
113
|
|
|
$this->expectExceptionMessage("Expecting array type at 'partition_columns'"); |
114
|
|
|
$platform->getCreateTableSQL($table); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|