Merge branch 'cassandra-2.2' into cassandra-3.0

This commit is contained in:
Sylvain Lebresne 2015-11-20 15:12:16 +01:00
commit 84750421a9
2 changed files with 23 additions and 6 deletions

View File

@ -10,6 +10,7 @@ Merged from 2.2:
* (Hadoop) fix splits calculation (CASSANDRA-10640)
* (Hadoop) ensure that Cluster instances are always closed (CASSANDRA-10058)
Merged from 2.1:
* (cqlsh) Support counters in COPY commands (CASSANDRA-9043)
* Try next replica if not possible to connect to primary replica on
ColumnFamilyRecordReader (CASSANDRA-2388)
* Limit window size in DTCS (CASSANDRA-10280)

View File

@ -2330,10 +2330,17 @@ class ImportProcess(mp.Process):
pk_cols = [col.name for col in table_meta.primary_key]
cqltypes = [table_meta.columns[name].cql_type for name in self.columns]
pk_indexes = [self.columns.index(col.name) for col in table_meta.primary_key]
query = 'INSERT INTO %s.%s (%s) VALUES (%%s)' % (
protect_name(self.ks),
protect_name(self.cf),
', '.join(protect_names(self.columns)))
is_counter_table = ("counter" in cqltypes)
if is_counter_table:
query = 'UPDATE %s.%s SET %%s WHERE %%s' % (
protect_name(table_meta.keyspace_name),
protect_name(table_meta.name))
else:
query = 'INSERT INTO %s.%s (%s) VALUES (%%s)' % (
protect_name(table_meta.keyspace_name),
protect_name(table_meta.name),
', '.join(protect_names(self.columns)))
# we need to handle some types specially
should_escape = [t in ('ascii', 'text', 'timestamp', 'date', 'time', 'inet') for t in cqltypes]
@ -2398,8 +2405,17 @@ class ImportProcess(mp.Process):
return
else:
row[i] = 'null'
full_query = query % (','.join(row),)
if is_counter_table:
where_clause = []
set_clause = []
for i, value in enumerate(row):
if i in pk_indexes:
where_clause.append("%s=%s" % (self.columns[i], value))
else:
set_clause.append("%s=%s+%s" % (self.columns[i], self.columns[i], value))
full_query = query % (','.join(set_clause), ' AND '.join(where_clause))
else:
full_query = query % (','.join(row),)
query_message = QueryMessage(
full_query, self.consistency_level, serial_consistency_level=None,
fetch_size=None, paging_state=None, timestamp=insert_timestamp)