Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 7cab32724 -> 50da872f2


(cqlsh) allow custom time_format for COPY TO

patch by Aaron Ploetz; reviewed by Carl Yeksigian for CASSANDRA-8970


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

Branch: refs/heads/cassandra-2.2
Commit: 3c0a1a5c1a77ca1148bef1712a2859400d85ea8c
Parents: 711870e
Author: Aaron Ploetz <aaronplo...@gmail.com>
Authored: Tue May 5 13:13:55 2015 -0400
Committer: Aleksey Yeschenko <alek...@apache.org>
Committed: Wed Oct 14 16:35:50 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt |  1 +
 bin/cqlsh   | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3c0a1a5c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9a82780..1338c6f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.12
+ * (cqlsh) allow custom time_format for COPY TO (CASSANDRA-8970)
  * Don't allow startup if the node's rack has changed (CASSANDRA-10242)
  * (cqlsh) show partial trace if incomplete after max_trace_wait 
(CASSANDRA-7645)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3c0a1a5c/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 2376d43..21f8ffe 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -409,7 +409,7 @@ def complete_copy_column_names(ctxt, cqlsh):
     return set(colnames[1:]) - set(existcols)
 
 
-COPY_OPTIONS = ('DELIMITER', 'QUOTE', 'ESCAPE', 'HEADER', 'ENCODING', 'NULL')
+COPY_OPTIONS = ('DELIMITER', 'QUOTE', 'ESCAPE', 'HEADER', 'ENCODING', 
'TIMEFORMAT', 'NULL')
 
 
 @cqlsh_syntax_completer('copyOption', 'optnames')
@@ -419,6 +419,7 @@ def complete_copy_options(ctxt, cqlsh):
     opts = set(COPY_OPTIONS) - set(optnames)
     if direction == 'FROM':
         opts -= ('ENCODING',)
+        opts -= ('TIMEFORMAT',)
     return opts
 
 
@@ -1499,12 +1500,14 @@ class Shell(cmd.Cmd):
 
         Available options and defaults:
 
-          DELIMITER=','    - character that appears between records
-          QUOTE='"'        - quoting character to be used to quote fields
-          ESCAPE='\'       - character to appear before the QUOTE char when 
quoted
-          HEADER=false     - whether to ignore the first line
-          NULL=''          - string that represents a null value
-          ENCODING='utf8'  - encoding for CSV output (COPY TO only)
+          DELIMITER=','           - character that appears between records
+          QUOTE='"'               - quoting character to be used to quote 
fields
+          ESCAPE='\'              - character to appear before the QUOTE char 
when quoted
+          HEADER=false            - whether to ignore the first line
+          NULL=''                 - string that represents a null value
+          ENCODING='utf8'         - encoding for CSV output (COPY TO only)
+          TIME_FORMAT=            - timestamp strftime format (COPY TO only)
+            '%Y-%m-%d %H:%M:%S%z'   defaults to time_format value in cqlshrc
 
         When entering CSV data on STDIN, you can use the sequence "\."
         on a line by itself to end the data input.
@@ -1802,6 +1805,7 @@ class Shell(cmd.Cmd):
 
     def perform_csv_export(self, ks, cf, columns, fname, opts):
         dialect_options = self.csv_dialect_defaults.copy()
+
         if 'quote' in opts:
             dialect_options['quotechar'] = opts.pop('quote')
         if 'escape' in opts:
@@ -1811,6 +1815,7 @@ class Shell(cmd.Cmd):
         encoding = opts.pop('encoding', 'utf8')
         nullval = opts.pop('null', '')
         header = bool(opts.pop('header', '').lower() == 'true')
+        timestamp_format = opts.pop('time_format', 
self.display_timestamp_format)
         if dialect_options['quotechar'] == dialect_options['escapechar']:
             dialect_options['doublequote'] = True
             del dialect_options['escapechar']
@@ -1833,7 +1838,7 @@ class Shell(cmd.Cmd):
 
         meter = RateMeter(10000)
         try:
-
+            dtformats = DateTimeFormat(timestamp_format, 
self.display_date_format, self.display_nanotime_format)
             dump = self.prep_export_dump(ks, cf, columns)
             writer = csv.writer(csvdest, **dialect_options)
             if header:
@@ -1841,7 +1846,7 @@ class Shell(cmd.Cmd):
             for row in dump:
                 fmt = lambda v: \
                     format_value(v, output_encoding=encoding, nullval=nullval,
-                                 time_format=self.display_time_format,
+                                 time_format=dtformats,
                                  
float_precision=self.display_float_precision).strval
                 writer.writerow(map(fmt, row.values()))
                 meter.increment()

Reply via email to