(cqlsh) allow setting TTL with COPY

patch by Stefania Alborghetti; reviewed by Adam Holmberg for
CASSANDRA-9494
This commit is contained in:
Stefania Alborghetti 2015-11-19 14:51:40 +08:00 committed by Aleksey Yeschenko
parent 622d1f7c0a
commit 99880d22de
3 changed files with 8 additions and 1 deletions

View File

@ -1,4 +1,5 @@
3.2
* (cqlsh) allow setting TTL with COPY (CASSANDRA-9494)
* Fix EstimatedHistogram creation in nodetool tablehistograms (CASSANDRA-10859)
* Establish bootstrap stream sessions sequentially (CASSANDRA-6992)
* Sort compactionhistory output by timestamp (CASSANDRA-10464)

View File

@ -460,7 +460,7 @@ def complete_copy_column_names(ctxt, cqlsh):
COPY_COMMON_OPTIONS = ['DELIMITER', 'QUOTE', 'ESCAPE', 'HEADER', 'NULL',
'MAXATTEMPTS', 'REPORTFREQUENCY']
COPY_FROM_OPTIONS = ['CHUNKSIZE', 'INGESTRATE', 'MAXBATCHSIZE', 'MINBATCHSIZE']
COPY_FROM_OPTIONS = ['CHUNKSIZE', 'INGESTRATE', 'MAXBATCHSIZE', 'MINBATCHSIZE', 'TTL']
COPY_TO_OPTIONS = ['ENCODING', 'TIMEFORMAT', 'PAGESIZE', 'PAGETIMEOUT', 'MAXREQUESTS']
@ -1812,6 +1812,7 @@ class Shell(cmd.Cmd):
MAXBATCHSIZE=20 - the maximum size of an import batch (COPY FROM)
MINBATCHSIZE=2 - the minimum size of an import batch (COPY FROM)
REPORTFREQUENCY=0.25 - the frequency with which we display status updates in seconds
TTL=3600 - the time to live in seconds, by default data will not expire (COPY FROM)
When entering CSV data on STDIN, you can use the sequence "\."
on a line by itself to end the data input.

View File

@ -83,6 +83,7 @@ def parse_options(shell, opts):
csv_options['maxbatchsize'] = int(opts.pop('maxbatchsize', 20))
csv_options['minbatchsize'] = int(opts.pop('minbatchsize', 2))
csv_options['reportfrequency'] = float(opts.pop('reportfrequency', 0.25))
csv_options['ttl'] = int(opts.pop('ttl', -1))
return csv_options, dialect_options, opts
@ -1063,6 +1064,7 @@ class ImportProcess(ChildProcess):
self.max_attempts = csv_options['maxattempts']
self.min_batch_size = csv_options['minbatchsize']
self.max_batch_size = csv_options['maxbatchsize']
self.ttl = csv_options['ttl']
self._session = None
@property
@ -1140,6 +1142,9 @@ class ImportProcess(ChildProcess):
protect_name(self.cf),
', '.join(protect_names(self.columns),),
', '.join(['?' for _ in self.columns]))
if self.ttl >= 0:
query += 'USING TTL %s' % (self.ttl,)
query_statement = self.session.prepare(query)
conv = ImportConversion(self, table_meta, query_statement)