Handle latest table options in CREATE statements
For PYTHON-51
This commit is contained in:
@@ -13,6 +13,8 @@ Bug Fixes
|
|||||||
KeyspaceMetadata and TableMetadata.
|
KeyspaceMetadata and TableMetadata.
|
||||||
* Decode TimestampType as DateType. (Cassandra replaced DateType with
|
* Decode TimestampType as DateType. (Cassandra replaced DateType with
|
||||||
TimestampType to fix sorting of pre-unix epoch dates in CASSANDRA-5723.)
|
TimestampType to fix sorting of pre-unix epoch dates in CASSANDRA-5723.)
|
||||||
|
* Handle latest table options when parsing the schema and generating
|
||||||
|
CREATE statements.
|
||||||
|
|
||||||
Other
|
Other
|
||||||
-----
|
-----
|
||||||
|
@@ -274,13 +274,13 @@ class Metadata(object):
|
|||||||
column_meta = self._build_column_metadata(table_meta, col_row)
|
column_meta = self._build_column_metadata(table_meta, col_row)
|
||||||
table_meta.columns[column_meta.name] = column_meta
|
table_meta.columns[column_meta.name] = column_meta
|
||||||
|
|
||||||
table_meta.options = self._build_table_options(row, is_compact)
|
table_meta.options = self._build_table_options(row)
|
||||||
|
table_meta.is_compact_storage = is_compact
|
||||||
return table_meta
|
return table_meta
|
||||||
|
|
||||||
def _build_table_options(self, row, is_compact_storage):
|
def _build_table_options(self, row):
|
||||||
""" Setup the mostly-non-schema table options, like caching settings """
|
""" Setup the mostly-non-schema table options, like caching settings """
|
||||||
options = dict((o, row.get(o)) for o in TableMetadata.recognized_options)
|
options = dict((o, row.get(o)) for o in TableMetadata.recognized_options if o in row)
|
||||||
options["is_compact_storage"] = is_compact_storage
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def _build_column_metadata(self, table_metadata, row):
|
def _build_column_metadata(self, table_metadata, row):
|
||||||
@@ -611,6 +611,8 @@ class TableMetadata(object):
|
|||||||
A dict mapping column names to :class:`.ColumnMetadata` instances.
|
A dict mapping column names to :class:`.ColumnMetadata` instances.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
is_compact_storage = False
|
||||||
|
|
||||||
options = None
|
options = None
|
||||||
"""
|
"""
|
||||||
A dict mapping table option names to their specific settings for this
|
A dict mapping table option names to their specific settings for this
|
||||||
@@ -618,11 +620,28 @@ class TableMetadata(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
recognized_options = (
|
recognized_options = (
|
||||||
"comment", "read_repair_chance", # "local_read_repair_chance",
|
"comment",
|
||||||
"replicate_on_write", "gc_grace_seconds", "bloom_filter_fp_chance",
|
"read_repair_chance",
|
||||||
"caching", "compaction_strategy_class", "compaction_strategy_options",
|
"dclocal_read_repair_chance",
|
||||||
"min_compaction_threshold", "max_compression_threshold",
|
"replicate_on_write",
|
||||||
"compression_parameters")
|
"gc_grace_seconds",
|
||||||
|
"bloom_filter_fp_chance",
|
||||||
|
"caching",
|
||||||
|
"compaction_strategy_class",
|
||||||
|
"compaction_strategy_options",
|
||||||
|
"min_compaction_threshold",
|
||||||
|
"max_compression_threshold",
|
||||||
|
"compression_parameters",
|
||||||
|
"min_index_interval",
|
||||||
|
"max_index_interval",
|
||||||
|
"index_interval",
|
||||||
|
"speculative_retry",
|
||||||
|
"rows_per_partition_to_cache",
|
||||||
|
"memtable_flush_period_in_ms",
|
||||||
|
"populate_io_cache_on_flush",
|
||||||
|
"compaction",
|
||||||
|
"compression",
|
||||||
|
"default_time_to_live")
|
||||||
|
|
||||||
def __init__(self, keyspace_metadata, name, partition_key=None, clustering_key=None, columns=None, options=None):
|
def __init__(self, keyspace_metadata, name, partition_key=None, clustering_key=None, columns=None, options=None):
|
||||||
self.keyspace = keyspace_metadata
|
self.keyspace = keyspace_metadata
|
||||||
@@ -693,7 +712,7 @@ class TableMetadata(object):
|
|||||||
ret += "%s) WITH " % ("\n" if formatted else "")
|
ret += "%s) WITH " % ("\n" if formatted else "")
|
||||||
|
|
||||||
option_strings = []
|
option_strings = []
|
||||||
if self.options.get("is_compact_storage"):
|
if self.is_compact_storage:
|
||||||
option_strings.append("COMPACT STORAGE")
|
option_strings.append("COMPACT STORAGE")
|
||||||
|
|
||||||
if self.clustering_key:
|
if self.clustering_key:
|
||||||
@@ -701,7 +720,7 @@ class TableMetadata(object):
|
|||||||
|
|
||||||
clustering_names = protect_names([c.name for c in self.clustering_key])
|
clustering_names = protect_names([c.name for c in self.clustering_key])
|
||||||
|
|
||||||
if self.options.get("is_compact_storage") and \
|
if self.is_compact_storage and \
|
||||||
not issubclass(self.comparator, types.CompositeType):
|
not issubclass(self.comparator, types.CompositeType):
|
||||||
subtypes = [self.comparator]
|
subtypes = [self.comparator]
|
||||||
else:
|
else:
|
||||||
@@ -715,20 +734,22 @@ class TableMetadata(object):
|
|||||||
cluster_str += "(%s)" % ", ".join(inner)
|
cluster_str += "(%s)" % ", ".join(inner)
|
||||||
option_strings.append(cluster_str)
|
option_strings.append(cluster_str)
|
||||||
|
|
||||||
option_strings.extend(map(self._make_option_str, self.recognized_options))
|
option_strings.extend(self._make_option_strings())
|
||||||
option_strings = filter(lambda x: x is not None, option_strings)
|
|
||||||
|
|
||||||
join_str = "\n AND " if formatted else " AND "
|
join_str = "\n AND " if formatted else " AND "
|
||||||
ret += join_str.join(option_strings)
|
ret += join_str.join(option_strings)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _make_option_str(self, name):
|
def _make_option_strings(self):
|
||||||
value = self.options.get(name)
|
ret = []
|
||||||
if value is not None:
|
for name, value in sorted(self.options.items()):
|
||||||
if name == "comment":
|
if value is not None:
|
||||||
value = value or ""
|
if name == "comment":
|
||||||
return "%s = %s" % (name, protect_value(value))
|
value = value or ""
|
||||||
|
ret.append("%s = %s" % (name, protect_value(value)))
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def protect_name(name):
|
def protect_name(name):
|
||||||
|
@@ -138,8 +138,8 @@ class SchemaMetadataTest(unittest.TestCase):
|
|||||||
self.assertEqual([], tablemeta.clustering_key)
|
self.assertEqual([], tablemeta.clustering_key)
|
||||||
self.assertEqual([u'a', u'b', u'c'], sorted(tablemeta.columns.keys()))
|
self.assertEqual([u'a', u'b', u'c'], sorted(tablemeta.columns.keys()))
|
||||||
|
|
||||||
for option in TableMetadata.recognized_options:
|
for option in tablemeta.options:
|
||||||
self.assertTrue(option in tablemeta.options)
|
self.assertIn(option, TableMetadata.recognized_options)
|
||||||
|
|
||||||
self.check_create_statement(tablemeta, create_statement)
|
self.check_create_statement(tablemeta, create_statement)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user