cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefa...@apache.org
Subject [3/6] cassandra git commit: Fix cqlsh COPY for dates before 1900
Date Wed, 22 Feb 2017 10:02:28 GMT
Fix cqlsh COPY for dates before 1900

patch by Stefania Alborghetti; reviewed by Tyler Hobbs for CASSANDRA-13185


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

Branch: refs/heads/trunk
Commit: f0502aa791897a30aea371a3032ea5ef679d25cc
Parents: 0eae908
Author: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Authored: Tue Feb 21 12:23:17 2017 +0000
Committer: Stefania Alborghetti <stefania.alborghetti@datastax.com>
Committed: Wed Feb 22 09:59:08 2017 +0000

----------------------------------------------------------------------
 CHANGES.txt                  |  2 ++
 pylib/cqlshlib/formatting.py | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f0502aa7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f2419d6..91a6b31 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 3.0.12
+ * Fix cqlsh COPY for dates before 1900 (CASSANDRA-13185)
+
 Merged from 2.2
  * Fix ColumnCounter::countAll behaviour for reverse queries (CASSANDRA-13222)
  * Exceptions encountered calling getSeeds() breaks OTC thread (CASSANDRA-13018)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f0502aa7/pylib/cqlshlib/formatting.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index dcd08da..097b1a7 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -246,7 +246,15 @@ def strftime(time_format, seconds, timezone=None):
     ret_dt = datetime_from_timestamp(seconds).replace(tzinfo=UTC())
     if timezone:
         ret_dt = ret_dt.astimezone(timezone)
-    return ret_dt.strftime(time_format)
+    try:
+        return ret_dt.strftime(time_format)
+    except ValueError:
+        # CASSANDRA-13185: if the date cannot be formatted as a string, return a string with
the milliseconds
+        # since the epoch. cqlsh does the exact same thing for values below datetime.MINYEAR
(1) or above
+        # datetime.MAXYEAR (9999). Some versions of strftime() also have problems for dates
between MIN_YEAR and 1900.
+        # cqlsh COPY assumes milliseconds from the epoch if it fails to parse a datetime
string, and so it is
+        # able to correctly import timestamps exported as milliseconds since the epoch.
+        return '%d' % (seconds * 1000.0)
 
 
 @formatter_for('Date')


Mime
View raw message