Fix formatting of duration in cqlsh

Patch by Maciej Sokol; reviewed by brandonwilliams and edimitrova for
CASSANDRA-18141
This commit is contained in:
Maciej Sokol 2023-01-11 09:56:29 +01:00 committed by Brandon Williams
parent ac8ddfb321
commit 175272fff4
4 changed files with 37 additions and 12 deletions

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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);