if k.startswith('%s_' % self.dialect.name)
)
+ partition_options = [
+ 'PARTITION_BY', 'PARTITIONS', 'SUBPARTITIONS',
+ 'SUBPARTITION_BY'
+ ]
+
+ nonpart_options = set(opts).difference(partition_options)
+ part_options = set(opts).intersection(partition_options)
+
for opt in topological.sort([
('DEFAULT_CHARSET', 'COLLATE'),
('DEFAULT_CHARACTER_SET', 'COLLATE'),
- ('PARTITION_BY', 'PARTITIONS'), # only for test consistency
- ], opts):
+ ], nonpart_options):
arg = opts[opt]
if opt in _reflection._options_of_type_string:
arg = "'%s'" % arg.replace("\\", "\\\\").replace("'", "''")
if opt in ('DATA_DIRECTORY', 'INDEX_DIRECTORY',
'DEFAULT_CHARACTER_SET', 'CHARACTER_SET',
'DEFAULT_CHARSET',
- 'DEFAULT_COLLATE', 'PARTITION_BY'):
+ 'DEFAULT_COLLATE'):
opt = opt.replace('_', ' ')
joiner = '='
if opt in ('TABLESPACE', 'DEFAULT CHARACTER SET',
- 'CHARACTER SET', 'COLLATE',
- 'PARTITION BY', 'PARTITIONS'):
+ 'CHARACTER SET', 'COLLATE'):
joiner = ' '
table_opts.append(joiner.join((opt, arg)))
+
+ for opt in topological.sort([
+ ('PARTITION_BY', 'PARTITIONS'),
+ ('PARTITION_BY', 'SUBPARTITION_BY'),
+ ('PARTITION_BY', 'SUBPARTITIONS'),
+ ('PARTITIONS', 'SUBPARTITIONS'),
+ ('PARTITIONS', 'SUBPARTITION_BY'),
+ ('SUBPARTITION_BY', 'SUBPARTITIONS')
+ ], part_options):
+ arg = opts[opt]
+ if opt in _reflection._options_of_type_string:
+ arg = "'%s'" % arg.replace("\\", "\\\\").replace("'", "''")
+
+ opt = opt.replace('_', ' ')
+ joiner = ' '
+
+ table_opts.append(joiner.join((opt, arg)))
+
return ' '.join(table_opts)
def visit_create_index(self, create):
')PARTITION BY KEY(other_id) PARTITIONS 2'
)
+ def test_create_table_with_subpartition(self):
+ t1 = Table(
+ 'testtable', MetaData(),
+ Column('id', Integer(), primary_key=True, autoincrement=True),
+ Column('other_id', Integer(), primary_key=True,
+ autoincrement=False),
+ mysql_partitions='2',
+ mysql_partition_by='KEY(other_id)',
+ mysql_subpartition_by="HASH(some_expr)",
+ mysql_subpartitions='2')
+ self.assert_compile(
+ schema.CreateTable(t1),
+ 'CREATE TABLE testtable ('
+ 'id INTEGER NOT NULL AUTO_INCREMENT, '
+ 'other_id INTEGER NOT NULL, '
+ 'PRIMARY KEY (id, other_id)'
+ ')PARTITION BY KEY(other_id) PARTITIONS 2 '
+ 'SUBPARTITION BY HASH(some_expr) SUBPARTITIONS 2'
+ )
+
def test_create_table_with_partition_hash(self):
t1 = Table(
'testtable', MetaData(),
')PARTITION BY HASH(other_id) PARTITIONS 2'
)
+ def test_create_table_with_partition_and_other_opts(self):
+ t1 = Table(
+ 'testtable', MetaData(),
+ Column('id', Integer(), primary_key=True, autoincrement=True),
+ Column('other_id', Integer(), primary_key=True,
+ autoincrement=False),
+ mysql_stats_sample_pages='2',
+ mysql_partitions='2', mysql_partition_by='HASH(other_id)')
+ self.assert_compile(
+ schema.CreateTable(t1),
+ 'CREATE TABLE testtable ('
+ 'id INTEGER NOT NULL AUTO_INCREMENT, '
+ 'other_id INTEGER NOT NULL, '
+ 'PRIMARY KEY (id, other_id)'
+ ')STATS_SAMPLE_PAGES=2 PARTITION BY HASH(other_id) PARTITIONS 2'
+ )
+
def test_inner_join(self):
t1 = table('t1', column('x'))
t2 = table('t2', column('y'))