Also quote column names when needed in CREATE stmts
Done for PYTHON-51
This commit is contained in:
@@ -8,7 +8,7 @@ Bug Fixes
|
||||
Cassandra is a multiple of the read buffer size. Previously, if no more data
|
||||
became available to read on the socket, the message would never be processed,
|
||||
resulting in an OperationTimedOut error.
|
||||
* Double quote keyspace and table names that require them (those using
|
||||
* Double quote keyspace, table and column names that require them (those using
|
||||
uppercase characters or keywords) when generating CREATE statements through
|
||||
KeyspaceMetadata and TableMetadata.
|
||||
* Decode TimestampType as DateType. (Cassandra replaced DateType with
|
||||
|
@@ -668,7 +668,7 @@ class TableMetadata(object):
|
||||
|
||||
columns = []
|
||||
for col in self.columns.values():
|
||||
columns.append("%s %s" % (col.name, col.typestring))
|
||||
columns.append("%s %s" % (protect_name(col.name), col.typestring))
|
||||
|
||||
if len(self.partition_key) == 1 and not self.clustering_key:
|
||||
columns[0] += " PRIMARY KEY"
|
||||
@@ -680,12 +680,12 @@ class TableMetadata(object):
|
||||
ret += "%s%sPRIMARY KEY (" % (column_join, padding)
|
||||
|
||||
if len(self.partition_key) > 1:
|
||||
ret += "(%s)" % ", ".join(col.name for col in self.partition_key)
|
||||
ret += "(%s)" % ", ".join(protect_name(col.name) for col in self.partition_key)
|
||||
else:
|
||||
ret += self.partition_key[0].name
|
||||
|
||||
if self.clustering_key:
|
||||
ret += ", %s" % ", ".join(col.name for col in self.clustering_key)
|
||||
ret += ", %s" % ", ".join(protect_name(col.name) for col in self.clustering_key)
|
||||
|
||||
ret += ")"
|
||||
|
||||
|
@@ -327,8 +327,12 @@ class TestCodeCoverage(unittest.TestCase):
|
||||
""" % (ksname,))
|
||||
session.execute("""
|
||||
CREATE TABLE "%s"."%s" (
|
||||
k int PRIMARY KEY,
|
||||
"MyColumn" int )
|
||||
k int,
|
||||
"A" int,
|
||||
"B" int,
|
||||
"MyColumn" int,
|
||||
PRIMARY KEY (k, "A"))
|
||||
WITH CLUSTERING ORDER BY ("A" DESC)
|
||||
""" % (ksname, cfname))
|
||||
session.execute("""
|
||||
CREATE INDEX myindex ON "%s"."%s" ("MyColumn")
|
||||
@@ -338,6 +342,11 @@ class TestCodeCoverage(unittest.TestCase):
|
||||
schema = ksmeta.export_as_string()
|
||||
self.assertIn('CREATE KEYSPACE "AnInterestingKeyspace"', schema)
|
||||
self.assertIn('CREATE TABLE "AnInterestingKeyspace"."AnInterestingTable"', schema)
|
||||
self.assertIn('"A" int', schema)
|
||||
self.assertIn('"B" int', schema)
|
||||
self.assertIn('"MyColumn" int', schema)
|
||||
self.assertIn('PRIMARY KEY (k, "A")', schema)
|
||||
self.assertIn('WITH CLUSTERING ORDER BY ("A" DESC)', schema)
|
||||
self.assertIn('CREATE INDEX myindex ON "AnInterestingKeyspace"."AnInterestingTable" ("MyColumn")', schema)
|
||||
|
||||
def test_already_exists_exceptions(self):
|
||||
|
Reference in New Issue
Block a user