You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2023/01/17 20:32:40 UTC

[cassandra] branch cassandra-4.0 updated: Fix formatting of duration in cqlsh

This is an automated email from the ASF dual-hosted git repository.

brandonwilliams pushed a commit to branch cassandra-4.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-4.0 by this push:
     new 175272fff4 Fix formatting of duration in cqlsh
175272fff4 is described below

commit 175272fff46f8441890e481c031ad521df9c9983
Author: Maciej Sokol <ma...@ericsson.com>
AuthorDate: Wed Jan 11 09:56:29 2023 +0100

    Fix formatting of duration in cqlsh
    
    Patch by Maciej Sokol; reviewed by brandonwilliams and edimitrova for
    CASSANDRA-18141
---
 CHANGES.txt                                |  1 +
 pylib/cqlshlib/formatting.py               |  2 +-
 pylib/cqlshlib/test/test_cqlsh_output.py   | 29 ++++++++++++++++++++++++++---
 pylib/cqlshlib/test/test_keyspace_init.cql | 17 +++++++++--------
 4 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 0f2d9e9812..87455991cd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0.8
+ * Fix formatting of duration in cqlsh (CASSANDRA-18141)
  * Fix sstable loading of keyspaces named snapshots or backups (CASSANDRA-14013)
  * Avoid ConcurrentModificationException in STCS/DTCS/TWCS.getSSTables (CASSANDRA-17977)
  * Restore internode custom tracing on 4.0's new messaging system (CASSANDRA-17981)
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index 5e2bb266df..e521544747 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -448,7 +448,7 @@ def append(builder, dividend, divisor, unit):
     if dividend == 0 or dividend < divisor:
         return dividend
 
-    builder.append(str(dividend / divisor))
+    builder.append(str(dividend // divisor))
     builder.append(unit)
     return dividend % divisor
 
diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py b/pylib/cqlshlib/test/test_cqlsh_output.py
index 5678def303..ed40683c7c 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -313,9 +313,9 @@ class TestCqlshOutput(BaseTestCase):
         # same query should show up as empty in cql 3
         self.assertQueriesGiveColoredOutput((
             (q, """
-             num | asciicol | bigintcol | blobcol | booleancol | decimalcol | doublecol | floatcol | intcol | smallintcol | textcol | timestampcol | tinyintcol | uuidcol | varcharcol | varintcol
-             RRR   MMMMMMMM   MMMMMMMMM   MMMMMMM   MMMMMMMMMM   MMMMMMMMMM   MMMMMMMMM   MMMMMMMM   MMMMMM   MMMMMMMMMMM   MMMMMMM   MMMMMMMMMMMM   MMMMMMMMMM   MMMMMMM   MMMMMMMMMM   MMMMMMMMM
-            -----+----------+-----------+---------+------------+------------+-----------+----------+--------+-------------+---------+--------------+------------+---------+------------+-----------
+             num | asciicol | bigintcol | blobcol | booleancol | decimalcol | doublecol | durationcol | floatcol | intcol | smallintcol | textcol | timestampcol | tinyintcol | uuidcol | varcharcol | varintcol
+             RRR   MMMMMMMM   MMMMMMMMM   MMMMMMM   MMMMMMMMMM   MMMMMMMMMM   MMMMMMMMM   MMMMMMMMMMM   MMMMMMMM   MMMMMM   MMMMMMMMMMM   MMMMMMM   MMMMMMMMMMMM   MMMMMMMMMM   MMMMMMM   MMMMMMMMMM   MMMMMMMMM
+            -----+----------+-----------+---------+------------+------------+-----------+-------------+----------+--------+-------------+---------+--------------+------------+---------+------------+-----------
 
 
             (0 rows)
@@ -567,6 +567,28 @@ class TestCqlshOutput(BaseTestCase):
             """, ),
         ))
 
+    def test_duration_output(self):
+        self.assertQueriesGiveColoredOutput((
+            ("select num, durationcol from has_all_types where num in (0, 1, 2, 3);", r"""
+             num | durationcol
+             RRR   MMMMMMMMMMM
+            -----+----------------
+
+               0 |            12h
+               G   GGGGGGGGGGGGGG
+               1 |         12h30m
+               G   GGGGGGGGGGGGGG
+               2 |      12h30m30s
+               G   GGGGGGGGGGGGGG
+               3 | 12h30m30s250ms
+               G   GGGGGGGGGGGGGG
+
+
+            (4 rows)
+            nnnnnnnn
+            """, ),
+        ))
+
     def test_prompt(self):
         with testrun_cqlsh(tty=True, keyspace=None, env=self.default_env) as c:
             self.assertTrue(c.output_header.splitlines()[-1].endswith('cqlsh> '))
@@ -649,6 +671,7 @@ class TestCqlshOutput(BaseTestCase):
                 booleancol boolean,
                 decimalcol decimal,
                 doublecol double,
+                durationcol duration,
                 floatcol float,
                 intcol int,
                 smallintcol smallint,
diff --git a/pylib/cqlshlib/test/test_keyspace_init.cql b/pylib/cqlshlib/test/test_keyspace_init.cql
index 3b9278ac0a..96bf9eab8d 100644
--- a/pylib/cqlshlib/test/test_keyspace_init.cql
+++ b/pylib/cqlshlib/test/test_keyspace_init.cql
@@ -25,6 +25,7 @@ CREATE TABLE has_all_types (
     booleancol boolean,
     decimalcol decimal,
     doublecol double,
+    durationcol duration,
     floatcol float,
     smallintcol smallint,
     textcol text,
@@ -36,32 +37,32 @@ CREATE TABLE has_all_types (
 ) WITH compression = {'sstable_compression':'LZ4Compressor'};
 
 INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
-                           decimalcol, doublecol, floatcol, smallintcol, textcol,
+                           decimalcol, doublecol, durationcol, floatcol, smallintcol, textcol,
                            timestampcol, tinyintcol, uuidcol, varcharcol, varintcol)
 VALUES (0, -12, 'abcdefg', 1234567890123456789, 0x000102030405fffefd, true,
-        19952.11882, 1.0, -2.1, 32767, 'Voilá!',
+        19952.11882, 1.0, 12h, -2.1, 32767, 'Voilá!',
         '2012-05-14 12:53:20+0000', 127, bd1924e1-6af8-44ae-b5e1-f24131dbd460, '"', 10000000000000000000000000);
 
 INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
-                           decimalcol, doublecol, floatcol, smallintcol, textcol,
+                           decimalcol, doublecol, durationcol, floatcol, smallintcol, textcol,
                            timestampcol, tinyintcol, uuidcol, varcharcol, varintcol)
 VALUES (1, 2147483647, '__!''$#@!~"', 9223372036854775807, 0xffffffffffffffffff, true,
-        0.00000000000001, 9999999.999, 99999.999, 32767, '∭Ƕ⑮ฑ➳❏''',
+        0.00000000000001, 9999999.999, 12h30m, 99999.999, 32767, '∭Ƕ⑮ฑ➳❏''',
         '1950-01-01+0000', 127, ffffffff-ffff-ffff-ffff-ffffffffffff, 'newline->
 <-', 9);
 
 INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
-                           decimalcol, doublecol, floatcol, smallintcol, textcol,
+                           decimalcol, doublecol, durationcol, floatcol, smallintcol, textcol,
                            timestampcol, tinyintcol, uuidcol, varcharcol, varintcol)
 VALUES (2, 0, '', 0, 0x, false,
-        0.0, 0.0, 0.0, 0, '',
+        0.0, 0.0, 12h30m30s, 0.0, 0, '',
         0, 0, 00000000-0000-0000-0000-000000000000, '', 0);
 
 INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
-                           decimalcol, doublecol, floatcol, smallintcol, textcol,
+                           decimalcol, doublecol, durationcol, floatcol, smallintcol, textcol,
                            timestampcol, tinyintcol, uuidcol, varcharcol, varintcol)
 VALUES (3, -2147483648, '''''''', -9223372036854775808, 0x80, false,
-        10.0000000000000, -1004.10, 100000000.9, 32767, '龍馭鬱',
+        10.0000000000000, -1004.10, 12h30m30s250ms, 100000000.9, 32767, '龍馭鬱',
         '2038-01-19T03:14-1200', 127, ffffffff-ffff-1fff-8fff-ffffffffffff,
 	    '''', -10000000000000000000000000);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org