Repository: cassandra
Updated Branches:
  refs/heads/trunk 622d1f7c0 -> 99880d22d


(cqlsh) allow setting TTL with COPY

patch by Stefania Alborghetti; reviewed by Adam Holmberg for
CASSANDRA-9494


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/99880d22
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/99880d22
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/99880d22

Branch: refs/heads/trunk
Commit: 99880d22de0023081a6d5829bef991eb96f7c342
Parents: 622d1f7
Author: Stefania Alborghetti <stefania.alborghe...@datastax.com>
Authored: Thu Nov 19 14:51:40 2015 +0800
Committer: Aleksey Yeschenko <alek...@apache.org>
Committed: Fri Dec 18 23:14:15 2015 +0000

----------------------------------------------------------------------
 CHANGES.txt                | 1 +
 bin/cqlsh.py               | 3 ++-
 pylib/cqlshlib/copyutil.py | 5 +++++
 3 files changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/99880d22/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5cbbb62..47863e9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99880d22/bin/cqlsh.py
----------------------------------------------------------------------
diff --git a/bin/cqlsh.py b/bin/cqlsh.py
index 0f6b39c..e48857d 100644
--- a/bin/cqlsh.py
+++ b/bin/cqlsh.py
@@ -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.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/99880d22/pylib/cqlshlib/copyutil.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py
index a117ec3..d7d7790 100644
--- a/pylib/cqlshlib/copyutil.py
+++ b/pylib/cqlshlib/copyutil.py
@@ -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)
 

Reply via email to