Merge pull request #201 from datastax/PYTHON-165

Handle CUSTOM index meta and string export
This commit is contained in:
Adam Holmberg
2014-10-13 14:55:51 -05:00
2 changed files with 40 additions and 8 deletions

View File

@@ -1,3 +1,21 @@
2.1.2
=====
In Progress
Features
--------
* Allow DCAwareRoundRobinPolicy to be constructed without a local_dc, defaulting
instead to the DC of a contact_point (PYTHON-126)
* Set routing key in BatchStatement.add() if none specified in batch (PYTHON-148)
* Improved feedback on ValueError using named_tuple_factory with invalid column names (PYTHON-122)
Bug Fixes
---------
* Handle Unauthorized message on schema_triggers query (PYTHON-155)
* Make execute_concurrent compatible with Python 2.6 (github-197)
* Pure Python sorted set in support of UDTs nested in collections (PYTON-167)
* Support CUSTOM index metadata and string export (PYTHON-165)
2.1.1
=====
September 11, 2014

View File

@@ -339,7 +339,9 @@ class Metadata(object):
index_name = row.get("index_name")
index_type = row.get("index_type")
if index_name or index_type:
return IndexMetadata(column_metadata, index_name, index_type)
options = row.get("index_options")
index_options = json.loads(options) if options else {}
return IndexMetadata(column_metadata, index_name, index_type, index_options)
else:
return None
@@ -1058,21 +1060,33 @@ class IndexMetadata(object):
index_type = None
""" A string representing the type of index. """
def __init__(self, column_metadata, index_name=None, index_type=None):
index_options = {}
""" A dict of index options. """
def __init__(self, column_metadata, index_name=None, index_type=None, index_options={}):
self.column = column_metadata
self.name = index_name
self.index_type = index_type
self.index_options = index_options
def as_cql_query(self):
"""
Returns a CQL query that can be used to recreate this index.
"""
table = self.column.table
return "CREATE INDEX %s ON %s.%s (%s)" % (
self.name, # Cassandra doesn't like quoted index names for some reason
protect_name(table.keyspace.name),
protect_name(table.name),
protect_name(self.column.name))
if self.index_type != "CUSTOM":
return "CREATE INDEX %s ON %s.%s (%s)" % (
self.name, # Cassandra doesn't like quoted index names for some reason
protect_name(table.keyspace.name),
protect_name(table.name),
protect_name(self.column.name))
else:
return "CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s'" % (
self.name, # Cassandra doesn't like quoted index names for some reason
protect_name(table.keyspace.name),
protect_name(table.name),
protect_name(self.column.name),
self.index_options["class_name"])
class TokenMap(object):
@@ -1269,4 +1283,4 @@ class TriggerMetadata(object):
protect_name(self.table.name),
protect_value(self.options['class'])
)
return ret
return ret