-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathtest_cqlsh.py
More file actions
2984 lines (2516 loc) · 145 KB
/
test_cqlsh.py
File metadata and controls
2984 lines (2516 loc) · 145 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding=utf-8
from __future__ import unicode_literals
import binascii
import csv
import datetime
import locale
import os
import re
import stat
import subprocess
import sys
import logging
import tempfile
import pytest
from decimal import Decimal
from distutils.version import LooseVersion
from tempfile import NamedTemporaryFile
from uuid import UUID, uuid4
from cassandra import InvalidRequest
from cassandra.concurrent import execute_concurrent_with_args
from cassandra.query import BatchStatement, BatchType
from ccmlib import common
from .cqlsh_tools import monkeypatch_driver, unmonkeypatch_driver
from dtest import Tester, create_ks, create_cf
from dtest_setup_overrides import DTestSetupOverrides
from tools.assertions import assert_all, assert_none
from tools.data import create_c1c2_table, insert_c1c2, rows_to_list
from tools.misc import ImmutableMapping, generate_ssl_stores
from . import util
since = pytest.mark.since
logger = logging.getLogger(__name__)
class CqlshMixin():
# If enabled, log all stdout/stderr of cqlsh commands
cqlsh_debug_enabled = False
def verify_output(self, query, node, expected):
cqlsh_options = ['-u', 'cassandra', '-p', 'cassandra']
if self.cluster.version() >= '4.1':
cqlsh_options.append('--insecure-password-without-warning')
output, err = self.run_cqlsh(node, query, cqlsh_options)
if common.is_win():
output = output.replace('\r', '')
assert 0 == len(err), "Failed to execute cqlsh: {}".format(err)
logger.debug(output)
assert expected in output, "Output \n {0} \n doesn't contain expected\n {1}".format(output, expected)
def _get_base_cli_args(self, node, cqlsh_options=None, env_vars=None):
if env_vars is None:
env_vars = {}
if cqlsh_options is None:
cqlsh_options = []
cdir = node.get_install_dir()
cli = os.path.join(cdir, 'bin', common.platform_binary('cqlsh'))
env = common.make_cassandra_env(cdir, node.get_path())
env['LANG'] = 'en_US.UTF-8'
env.update(env_vars)
if self.cluster.version() >= LooseVersion('2.1'):
host = node.network_interfaces['binary'][0]
port = node.network_interfaces['binary'][1]
else:
host = node.network_interfaces['thrift'][0]
port = node.network_interfaces['thrift'][1]
return cli, cqlsh_options + [host, str(port)], env
def run_cqlsh(self, node, cmds, cqlsh_options=None, env_vars=None):
"""
Local version of run_cqlsh to open a cqlsh subprocess with
additional environment variables.
"""
cli, args, env = self._get_base_cli_args(node, cqlsh_options, env_vars)
sys.stdout.flush()
p = subprocess.Popen([cli] + args, env=env, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stdout=subprocess.PIPE,
universal_newlines=True)
for cmd in cmds.split(';'):
p.stdin.write(cmd + ';\n')
p.stdin.write("quit;\n")
stdout, stderr = p.communicate()
if self.cqlsh_debug_enabled:
cmd = " ".join([cli] + args)
logger.debug("Cqlsh command: " + cmd)
logger.debug("Cqlsh command stdout:\n" + stdout)
logger.debug("Cqlsh command stderr:\n" + stderr)
return stdout, stderr
class TestCqlsh(Tester, CqlshMixin):
# override cluster options to enable user defined functions
# currently only needed for test_describe
@pytest.fixture
def fixture_dtest_setup_overrides(self, dtest_config):
dtest_setup_overrides = DTestSetupOverrides()
if '3.0' <= dtest_config.cassandra_version_from_build < '4.2':
dtest_setup_overrides.cluster_options = ImmutableMapping({'enable_user_defined_functions': 'true',
'enable_scripted_user_defined_functions': 'true'})
else:
dtest_setup_overrides.cluster_options = ImmutableMapping({'enable_user_defined_functions': 'true'})
return dtest_setup_overrides
@classmethod
def setUpClass(cls):
cls._cached_driver_methods = monkeypatch_driver()
if locale.getpreferredencoding() != 'UTF-8':
os.environ['LC_CTYPE'] = 'en_US.utf8'
@classmethod
def tearDownClass(cls):
unmonkeypatch_driver(cls._cached_driver_methods)
def tearDown(self):
if hasattr(self, 'tempfile') and not common.is_win():
os.unlink(self.tempfile.name)
super(TestCqlsh, self).tearDown()
@pytest.mark.depends_cqlshlib
@since('2.1.9')
def test_pycodestyle_compliance(self):
"""
@jira_ticket CASSANDRA-10066
Checks that cqlsh is compliant with pycodestyle (formally known as pep8) with the following command:
pycodestyle --ignore E501,E402,E731,W503 pylib/cqlshlib/*.py bin/cqlsh.py
"""
cluster = self.cluster
if cluster.version() < LooseVersion('2.2'):
cqlsh_path = os.path.join(cluster.get_install_dir(), 'bin', 'cqlsh')
else:
cqlsh_path = os.path.join(cluster.get_install_dir(), 'bin', 'cqlsh.py')
cqlshlib_path = os.path.join(cluster.get_install_dir(), 'pylib', 'cqlshlib')
cqlshlib_paths = os.listdir(cqlshlib_path)
cqlshlib_paths = [os.path.join(cqlshlib_path, x) for x in cqlshlib_paths if '.py' in x and '.pyc' not in x]
cmds = ['pycodestyle', '--ignore', 'E501,E402,E731,W503', cqlsh_path] + cqlshlib_paths
logger.debug(cmds)
# 3.7 adds a text=True option which converts stdout/stderr to str type, until then
# when printing out need to convert in order to avoid assert failing as the type
# does not have an encoding
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
assert 0 == len(stdout), stdout.decode("utf-8")
assert 0 == len(stderr), stderr.decode("utf-8")
def test_simple_insert(self):
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.run_cqlsh(cmds="""
CREATE KEYSPACE simple WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
use simple;
create TABLE simple (id int PRIMARY KEY , value text ) ;
insert into simple (id, value) VALUES (1, 'one');
insert into simple (id, value) VALUES (2, 'two');
insert into simple (id, value) VALUES (3, 'three');
insert into simple (id, value) VALUES (4, 'four');
insert into simple (id, value) VALUES (5, 'five')""")
session = self.patient_cql_connection(node1)
rows = list(session.execute("select id, value from simple.simple"))
assert {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five'} == {k: v for k, v in rows}
def test_tls(self):
""" Test that TLSv1.2 connections work CASSANDRA-16695 """
generate_ssl_stores(self.fixture_dtest_setup.test_path)
self.cluster.set_configuration_options({
'client_encryption_options': {
'enabled': True,
'optional': False,
'protocol': 'TLSv1.2',
'keystore': os.path.join(self.fixture_dtest_setup.test_path, 'keystore.jks'),
'keystore_password': 'cassandra'
}
})
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
out, err = self.run_cqlsh(node1, cmds="DESCRIBE KEYSPACES", cqlsh_options=['--ssl'], env_vars={'SSL_CERTFILE': os.path.join(self.fixture_dtest_setup.test_path, 'ccm_node.cer')})
assert err == ''
def test_lwt(self):
"""
Test LWT inserts and updates.
@jira_ticket CASSANDRA-11003
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.run_cqlsh(cmds="""
CREATE KEYSPACE lwt WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
CREATE TABLE lwt.lwt (id int PRIMARY KEY , value text)""")
def assert_applied(stmt, node=node1):
expected_substring = '[applied]'
output, _ = self.run_cqlsh(node, stmt)
msg = '{exp} not found in output from {stmt}: {routput}'.format(
exp=repr(expected_substring),
stmt=repr(stmt),
routput=repr(output)
)
assert expected_substring in output, msg
assert_applied("INSERT INTO lwt.lwt (id, value) VALUES (1, 'one') IF NOT EXISTS")
assert_applied("INSERT INTO lwt.lwt (id, value) VALUES (1, 'one') IF NOT EXISTS")
assert_applied("UPDATE lwt.lwt SET value = 'one' WHERE id = 1 IF value = 'one'")
assert_applied("UPDATE lwt.lwt SET value = 'one' WHERE id = 1 IF value = 'zzz'")
@since('2.2')
def test_past_and_future_dates(self):
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.run_cqlsh(cmds="""
CREATE KEYSPACE simple WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
use simple;
create TABLE simpledate (id int PRIMARY KEY , value timestamp ) ;
insert into simpledate (id, value) VALUES (1, '2143-04-19 11:21:01+0000');
insert into simpledate (id, value) VALUES (2, '1943-04-19 11:21:01+0000')""")
session = self.patient_cql_connection(node1)
list(session.execute("select id, value from simple.simpledate"))
output, err = self.run_cqlsh(node1, 'use simple; SELECT * FROM simpledate')
if self.cluster.version() >= LooseVersion('3.4'):
assert "2143-04-19 11:21:01.000000+0000" in output
assert "1943-04-19 11:21:01.000000+0000" in output
else:
assert "2143-04-19 11:21:01+0000" in output
assert "1943-04-19 11:21:01+0000" in output
@since('3.4')
def test_sub_second_precision(self):
"""
Test that we can query at millisecond precision.
@jira_ticket 10428
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.run_cqlsh(cmds="""
CREATE KEYSPACE simple WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
use simple;
create TABLE testsubsecond (id int, subid timestamp, value text, primary key (id, subid));
insert into testsubsecond (id, subid, value) VALUES (1, '1943-06-19 11:21:01.123+0000', 'abc');
insert into testsubsecond (id, subid, value) VALUES (2, '1943-06-19 11:21:01+0000', 'def')""")
output, err, _ = node1.run_cqlsh(cmds="use simple; SELECT * FROM testsubsecond "
"WHERE id = 1 AND subid = '1943-06-19 11:21:01.123+0000'")
logger.debug(output)
assert "1943-06-19 11:21:01.123000+0000" in output
assert "1943-06-19 11:21:01.000000+0000" not in output
output, err, _ = node1.run_cqlsh(cmds="use simple; SELECT * FROM testsubsecond "
"WHERE id = 2 AND subid = '1943-06-19 11:21:01+0000'")
logger.debug(output)
assert "1943-06-19 11:21:01.000000+0000" in output
assert "1943-06-19 11:21:01.123000+0000" not in output
def verify_glass(self, node):
session = self.patient_cql_connection(node)
def verify_varcharmap(map_name, expected, encode_value=False):
rows = list(session.execute(("SELECT %s FROM testks.varcharmaptable WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';" % map_name)))
if encode_value:
got = {k.encode("utf-8"): v.encode("utf-8") for k, v in rows[0][0].items()}
else:
got = {k: v for k, v in rows[0][0].items()}
assert got == expected
verify_varcharmap('varcharasciimap', {
'Vitrum edere possum, mihi non nocet.': 'Hello',
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 'My',
'Можам да јадам стакло, а не ме штета.': 'Name',
'I can eat glass and it does not hurt me': 'Is'
})
verify_varcharmap('varcharbigintmap', {
'Vitrum edere possum, mihi non nocet.': 5100003,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -45,
'Можам да јадам стакло, а не ме штета.': 12300,
'I can eat glass and it does not hurt me': 0
})
verify_varcharmap('varcharblobmap', {
'Vitrum edere possum, mihi non nocet.': binascii.a2b_hex("FEED103A"),
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': binascii.a2b_hex("DEADBEEF"),
'Можам да јадам стакло, а не ме штета.': binascii.a2b_hex("BEEFBEEF"),
'I can eat glass and it does not hurt me': binascii.a2b_hex("FEEB")
})
verify_varcharmap('varcharbooleanmap', {
'Vitrum edere possum, mihi non nocet.': True,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': False,
'Можам да јадам стакло, а не ме штета.': False,
'I can eat glass and it does not hurt me': False
})
verify_varcharmap('varchardecimalmap', {
'Vitrum edere possum, mihi non nocet.': Decimal('50'),
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': Decimal('-20.4'),
'Можам да јадам стакло, а не ме штета.': Decimal('11234234.3'),
'I can eat glass and it does not hurt me': Decimal('10.0')
})
verify_varcharmap('varchardoublemap', {
'Vitrum edere possum, mihi non nocet.': 4234243,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -432.311,
'Можам да јадам стакло, а не ме штета.': 3.1415,
'I can eat glass and it does not hurt me': 20000.0
})
verify_varcharmap('varcharfloatmap', {
'Vitrum edere possum, mihi non nocet.': 10.0,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -234.3000030517578,
'Можам да јадам стакло, а не ме штета.': -234234,
'I can eat glass and it does not hurt me': 1000.5
})
verify_varcharmap('varcharintmap', {
'Vitrum edere possum, mihi non nocet.': 1,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 2,
'Можам да јадам стакло, а не ме штета.': -3,
'I can eat glass and it does not hurt me': -500
})
verify_varcharmap('varcharinetmap', {
'Vitrum edere possum, mihi non nocet.': '192.168.0.1',
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': '127.0.0.1',
'Можам да јадам стакло, а не ме штета.': '8.8.8.8',
'I can eat glass and it does not hurt me': '8.8.4.4'
})
verify_varcharmap('varchartextmap', {
'Vitrum edere possum, mihi non nocet.': 'Once I went',
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 'On a trip',
'Можам да јадам стакло, а не ме штета.': 'Across',
'I can eat glass and it does not hurt me': 'The '
})
verify_varcharmap('varchartimestampmap', {
'Vitrum edere possum, mihi non nocet.': datetime.datetime(2013, 6, 19, 3, 21, 1),
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': datetime.datetime(1985, 8, 3, 4, 21, 1),
'Можам да јадам стакло, а не ме штета.': datetime.datetime(2000, 1, 1, 0, 20, 1),
'I can eat glass and it does not hurt me': datetime.datetime(1942, 3, 11, 5, 21, 1)
})
verify_varcharmap('varcharuuidmap', {
'Vitrum edere possum, mihi non nocet.': UUID('7787064c-ce54-4324-abdd-05775b89ead7'),
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': UUID('1df0b6ac-f3d3-456c-8b78-2bc70e585107'),
'Можам да јадам стакло, а не ме штета.': UUID('e2ed2164-31dc-42cb-8ee9-47376e071210'),
'I can eat glass and it does not hurt me': UUID('a487fe45-8af5-4454-ac66-2614286d7e89')
})
verify_varcharmap('varchartimeuuidmap', {
'Vitrum edere possum, mihi non nocet.': UUID('4a36c100-d8ec-11e2-a28f-0800200c9a66'),
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': UUID('670c7f90-d8ec-11e2-a28f-0800200c9a66'),
'Можам да јадам стакло, а не ме штета.': UUID('750c2d70-d8ec-11e2-a28f-0800200c9a66'),
'I can eat glass and it does not hurt me': UUID('80d74810-d8ec-11e2-a28f-0800200c9a66')
})
verify_varcharmap('varcharvarcharmap', {
'Vitrum edere possum, mihi non nocet.': '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜',
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': ' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑',
'Можам да јадам стакло, а не ме штета.': 'Можам да јадам стакло, а не ме штета.',
'I can eat glass and it does not hurt me': 'I can eat glass and it does not hurt me'
})
verify_varcharmap('varcharvarintmap', {
'Vitrum edere possum, mihi non nocet.': 1010010101020400204143243,
' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -40,
'Можам да јадам стакло, а не ме штета.': 110230,
'I can eat glass and it does not hurt me': 1400
})
output, _ = self.run_cqlsh(node, 'use testks; SELECT * FROM varcharmaptable', ['--encoding=utf-8'])
assert output.count('Можам да јадам стакло, а не ме штета.') == 16
assert output.count(' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑') == 16
assert output.count('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜') == 2
def test_eat_glass(self):
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
cmds = """create KEYSPACE testks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
use testks;
CREATE TABLE varcharmaptable (
varcharkey varchar ,
varcharasciimap map<varchar, ascii>,
varcharbigintmap map<varchar, bigint>,
varcharblobmap map<varchar, blob>,
varcharbooleanmap map<varchar, boolean>,
varchardecimalmap map<varchar, decimal>,
varchardoublemap map<varchar, double>,
varcharfloatmap map<varchar, float>,
varcharintmap map<varchar, int>,
varcharinetmap map<varchar, inet>,
varchartextmap map<varchar, text>,
varchartimestampmap map<varchar, timestamp>,
varcharuuidmap map<varchar, uuid>,
varchartimeuuidmap map<varchar, timeuuid>,
varcharvarcharmap map<varchar, varchar>,
varcharvarintmap map<varchar, varint>,
PRIMARY KEY (varcharkey));
INSERT INTO varcharmaptable (varcharkey, varcharasciimap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 'My','Можам да јадам стакло, а не ме штета.': 'Name','I can eat glass and it does not hurt me': 'Is'} );
UPDATE varcharmaptable SET varcharasciimap = varcharasciimap + {'Vitrum edere possum, mihi non nocet.':'Cassandra'} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharasciimap['Vitrum edere possum, mihi non nocet.'] = 'Hello' WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharbigintmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -45,'Можам да јадам стакло, а не ме штета.': 12300,'I can eat glass and it does not hurt me': 0} );
UPDATE varcharmaptable SET varcharbigintmap = varcharbigintmap + {'Vitrum edere possum, mihi non nocet.':23} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharbigintmap['Vitrum edere possum, mihi non nocet.'] = 5100003 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharblobmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 0xDEADBEEF,'Можам да јадам стакло, а не ме штета.': 0xBEEFBEEF,'I can eat glass and it does not hurt me': 0xFEEB} );
UPDATE varcharmaptable SET varcharblobmap = varcharblobmap + {'Vitrum edere possum, mihi non nocet.':0x10} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharblobmap['Vitrum edere possum, mihi non nocet.'] = 0xFEED103A WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharbooleanmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': FALSE,'Можам да јадам стакло, а не ме штета.': FALSE,'I can eat glass and it does not hurt me': FALSE} );
UPDATE varcharmaptable SET varcharbooleanmap = varcharbooleanmap + {'Vitrum edere possum, mihi non nocet.':TRUE} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharbooleanmap['Vitrum edere possum, mihi non nocet.'] = TRUE WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varchardecimalmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -20.4,'Можам да јадам стакло, а не ме штета.': 11234234.3,'I can eat glass and it does not hurt me': 10.0} );
UPDATE varcharmaptable SET varchardecimalmap = varchardecimalmap + {'Vitrum edere possum, mihi non nocet.':0.0} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varchardecimalmap['Vitrum edere possum, mihi non nocet.'] = 50.0 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varchardoublemap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -432.311,'Можам да јадам стакло, а не ме штета.': 3.1415,'I can eat glass and it does not hurt me': 20000.0} );
UPDATE varcharmaptable SET varchardoublemap = varchardoublemap + {'Vitrum edere possum, mihi non nocet.':11} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varchardoublemap['Vitrum edere possum, mihi non nocet.'] = 4234243 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharfloatmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -234.3,'Можам да јадам стакло, а не ме штета.': -234234,'I can eat glass and it does not hurt me': 1000.5} );
UPDATE varcharmaptable SET varcharfloatmap = varcharfloatmap + {'Vitrum edere possum, mihi non nocet.':-3.14} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharfloatmap['Vitrum edere possum, mihi non nocet.'] = 10.0 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharintmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 2,'Можам да јадам стакло, а не ме штета.': -3,'I can eat glass and it does not hurt me': -500} );
UPDATE varcharmaptable SET varcharintmap = varcharintmap + {'Vitrum edere possum, mihi non nocet.':20000} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharintmap['Vitrum edere possum, mihi non nocet.'] = 1 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharinetmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': '127.0.0.1','Можам да јадам стакло, а не ме штета.': '8.8.8.8','I can eat glass and it does not hurt me': '8.8.4.4'} );
UPDATE varcharmaptable SET varcharinetmap = varcharinetmap + {'Vitrum edere possum, mihi non nocet.':'241.30.12.24'} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharinetmap['Vitrum edere possum, mihi non nocet.'] = '192.168.0.1' WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varchartextmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 'On a trip','Можам да јадам стакло, а не ме штета.': 'Across','I can eat glass and it does not hurt me': 'The '} );
UPDATE varcharmaptable SET varchartextmap = varchartextmap + {'Vitrum edere possum, mihi non nocet.':'Sea'} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varchartextmap['Vitrum edere possum, mihi non nocet.'] = 'Once I went' WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varchartimestampmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': '1985-08-03T04:21:01+0000','Можам да јадам стакло, а не ме штета.': '2000-01-01T00:20:01+0000','I can eat glass and it does not hurt me': '1942-03-11T05:21:01+0000'} );
UPDATE varcharmaptable SET varchartimestampmap = varchartimestampmap + {'Vitrum edere possum, mihi non nocet.':'2043-11-04T11:21:01+0000'} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varchartimestampmap['Vitrum edere possum, mihi non nocet.'] = '2013-06-19T03:21:01+0000' WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharuuidmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 1df0b6ac-f3d3-456c-8b78-2bc70e585107,'Можам да јадам стакло, а не ме штета.': e2ed2164-31dc-42cb-8ee9-47376e071210,'I can eat glass and it does not hurt me': a487fe45-8af5-4454-ac66-2614286d7e89} );
UPDATE varcharmaptable SET varcharuuidmap = varcharuuidmap + {'Vitrum edere possum, mihi non nocet.':d25bdfc7-eb81-472c-bf5b-b4e6afdf66c2} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharuuidmap['Vitrum edere possum, mihi non nocet.'] = 7787064c-ce54-4324-abdd-05775b89ead7 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varchartimeuuidmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': 670c7f90-d8ec-11e2-a28f-0800200c9a66,'Можам да јадам стакло, а не ме штета.': 750c2d70-d8ec-11e2-a28f-0800200c9a66,'I can eat glass and it does not hurt me': 80d74810-d8ec-11e2-a28f-0800200c9a66} );
UPDATE varcharmaptable SET varchartimeuuidmap = varchartimeuuidmap + {'Vitrum edere possum, mihi non nocet.':93e276f0-d8ec-11e2-a28f-0800200c9a66} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varchartimeuuidmap['Vitrum edere possum, mihi non nocet.'] = 4a36c100-d8ec-11e2-a28f-0800200c9a66 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharvarcharmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': ' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑','Можам да јадам стакло, а не ме штета.': 'Можам да јадам стакло, а не ме штета.','I can eat glass and it does not hurt me': 'I can eat glass and it does not hurt me'} );
UPDATE varcharmaptable SET varcharvarcharmap = varcharvarcharmap + {'Vitrum edere possum, mihi non nocet.':'Vitrum edere possum, mihi non nocet.'} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharvarcharmap['Vitrum edere possum, mihi non nocet.'] = '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜' WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
INSERT INTO varcharmaptable (varcharkey, varcharvarintmap ) VALUES ('᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜', {' ⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑': -40,'Можам да јадам стакло, а не ме штета.': 110230,'I can eat glass and it does not hurt me': 1400} );
UPDATE varcharmaptable SET varcharvarintmap = varcharvarintmap + {'Vitrum edere possum, mihi non nocet.':20000} WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜';
UPDATE varcharmaptable SET varcharvarintmap['Vitrum edere possum, mihi non nocet.'] = 1010010101020400204143243 WHERE varcharkey= '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜'
"""
node1.run_cqlsh(cmds=cmds)
self.verify_glass(node1)
def test_source_glass(self):
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.run_cqlsh(cmds="SOURCE 'cqlsh_tests/glass.cql'")
self.verify_glass(node1)
def test_unicode_syntax_error(self):
"""
Ensure that syntax errors involving unicode are handled correctly.
@jira_ticket CASSANDRA-11626
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
cmds = "ä;"
if self.cluster.version() >= LooseVersion('3.0'):
_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmds)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
err = node1.run_cqlsh(cmds=cmds).stderr
assert 'Invalid syntax' in err
assert 'ä' in err
@since('2.2')
def test_unicode_invalid_request_error(self):
"""
Ensure that invalid request errors involving unicode are handled correctly.
@jira_ticket CASSANDRA-11626
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
cmd = '''create keyspace "ä" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};'''
options = ["--debug"]
if self.cluster.version() >= LooseVersion('3.0'):
_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmd, cqlsh_options=options)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
err = node1.run_cqlsh(cmds=cmd, cqlsh_options=options).stderr
if self.cluster.version() >= LooseVersion('4.0'):
assert "Keyspace name must not be empty, more than 48 characters long, or contain non-alphanumeric-underscore characters (got 'ä')" in err
else:
assert '"ä" is not a valid keyspace name' in err
def test_with_empty_values(self):
"""
CASSANDRA-7196. Make sure the server returns empty values and CQLSH prints them properly
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
cmds = """create keyspace CASSANDRA_7196 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1} ;
use CASSANDRA_7196;
CREATE TABLE has_all_types (
num int PRIMARY KEY,
intcol int,
asciicol ascii,
bigintcol bigint,
blobcol blob,
booleancol boolean,
decimalcol decimal,
doublecol double,
floatcol float,
textcol text,
timestampcol timestamp,
uuidcol uuid,
varcharcol varchar,
varintcol varint
) WITH compression = {'sstable_compression':'LZ4Compressor'};
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
decimalcol, doublecol, floatcol, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (0, -12, 'abcdefg', 1234567890123456789, 0x000102030405fffefd, true,
19952.11882, 1.0, -2.1, 'Voilá!', '2012-05-14 12:53:20+0000',
bd1924e1-6af8-44ae-b5e1-f24131dbd460, '"', 10000000000000000000000000);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
decimalcol, doublecol, floatcol, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (1, 2147483647, '__!''$#@!~"', 9223372036854775807, 0xffffffffffffffffff, true,
0.00000000000001, 9999999.999, 99999.99, '∭Ƕ⑮ฑ➳❏''', '1900-01-01+0000',
ffffffff-ffff-ffff-ffff-ffffffffffff, 'newline->
<-', 9);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
decimalcol, doublecol, floatcol, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (2, 0, '', 0, 0x, false,
0.0, 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, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (3, -2147483648, '''''''', -9223372036854775808, 0x80, false,
10.0000000000000, -1004.10, 100000000.9, '龍馭鬱', '2038-01-19T03:14-1200',
ffffffff-ffff-1fff-8fff-ffffffffffff, '''', -10000000000000000000000000);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
decimalcol, doublecol, floatcol, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (4, blobAsInt(0x), '', blobAsBigint(0x), 0x, blobAsBoolean(0x), blobAsDecimal(0x),
blobAsDouble(0x), blobAsFloat(0x), '', blobAsTimestamp(0x), blobAsUuid(0x), '',
blobAsVarint(0x))"""
node1.run_cqlsh(cmds=cmds)
select_cmd = "select intcol, bigintcol, varintcol from CASSANDRA_7196.has_all_types where num in (0, 1, 2, 3, 4)"
output, err = self.run_cqlsh(node1, cmds=select_cmd)
if common.is_win():
output = output.replace('\r', '')
expected = """
intcol | bigintcol | varintcol
-------------+----------------------+-----------------------------
-12 | 1234567890123456789 | 10000000000000000000000000
2147483647 | 9223372036854775807 | 9
0 | 0 | 0
-2147483648 | -9223372036854775808 | -10000000000000000000000000
| | \n\n(5 rows)"""
assert expected in output, "Output \n {0} \n doesn't contain expected\n {1}".format(output, expected)
def test_tracing_from_system_traces(self):
self.cluster.populate(1).start()
node1, = self.cluster.nodelist()
session = self.patient_cql_connection(node1)
create_ks(session, 'ks', 1)
create_c1c2_table(self, session)
insert_c1c2(session, n=100)
out, err = self.run_cqlsh(node1, 'TRACING ON; SELECT * FROM ks.cf')
assert 'Tracing session: ' in out
out, err = self.run_cqlsh(node1, 'TRACING ON; SELECT * FROM system_traces.events')
assert 'Tracing session: ' not in out
out, err = self.run_cqlsh(node1, 'TRACING ON; SELECT * FROM system_traces.sessions')
assert 'Tracing session: ' not in out
def test_select_element_inside_udt(self):
self.cluster.populate(1).start()
node1, = self.cluster.nodelist()
session = self.patient_cql_connection(node1)
create_ks(session, 'ks', 1)
session.execute("""
CREATE TYPE address (
street text,
city text,
zip_code int,
phones set<text>
);""")
session.execute("""CREATE TYPE fullname (
firstname text,
lastname text
);""")
session.execute("""CREATE TABLE users (
id uuid PRIMARY KEY,
name FROZEN <fullname>,
addresses map<text, FROZEN <address>>
);""")
session.execute("""INSERT INTO users (id, name)
VALUES (62c36092-82a1-3a00-93d1-46196ee77204, {firstname: 'Marie-Claude', lastname: 'Josset'});
""")
out, err = self.run_cqlsh(node1, "SELECT name.lastname FROM ks.users WHERE id=62c36092-82a1-3a00-93d1-46196ee77204")
assert 'list index out of range' not in err
# If this assertion fails check CASSANDRA-7891
# If enabled, log all stdout/stderr of cqlsh commands
cqlsh_debug_enabled = False
def test_list_queries(self):
config = {'authenticator': 'org.apache.cassandra.auth.PasswordAuthenticator',
'authorizer': 'org.apache.cassandra.auth.CassandraAuthorizer',
'permissions_validity_in_ms': '0'}
self.cluster.set_configuration_options(values=config)
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
node1.watch_log_for('Created default superuser')
conn = self.patient_cql_connection(node1, user='cassandra', password='cassandra')
conn.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
conn.execute("CREATE TABLE ks.t1 (k int PRIMARY KEY, v int)")
conn.execute("CREATE USER user1 WITH PASSWORD 'user1'")
conn.execute("GRANT ALL ON ks.t1 TO user1")
if self.cluster.version() >= LooseVersion('4.0'):
self.verify_output("LIST USERS", node1, """
name | super | datacenters
-----------+-------+-------------
cassandra | True | ALL
user1 | False | ALL
(2 rows)
""")
elif self.cluster.version() >= LooseVersion('2.2'):
self.verify_output("LIST USERS", node1, """
name | super
-----------+-------
cassandra | True
user1 | False
(2 rows)
""")
else:
self.verify_output("LIST USERS", node1, """
name | super
-----------+-------
user1 | False
cassandra | True
(2 rows)
""")
if self.cluster.version() >= LooseVersion('4.2'):
self.verify_output("LIST ALL PERMISSIONS OF user1", node1, """
role | username | resource | permission
-------+----------+---------------+---------------
user1 | user1 | <table ks.t1> | ALTER
user1 | user1 | <table ks.t1> | DROP
user1 | user1 | <table ks.t1> | SELECT
user1 | user1 | <table ks.t1> | MODIFY
user1 | user1 | <table ks.t1> | AUTHORIZE
user1 | user1 | <table ks.t1> | UNMASK
user1 | user1 | <table ks.t1> | SELECT_MASKED
(7 rows)
""")
elif self.cluster.version() >= LooseVersion('2.2'):
self.verify_output("LIST ALL PERMISSIONS OF user1", node1, """
role | username | resource | permission
-------+----------+---------------+------------
user1 | user1 | <table ks.t1> | ALTER
user1 | user1 | <table ks.t1> | DROP
user1 | user1 | <table ks.t1> | SELECT
user1 | user1 | <table ks.t1> | MODIFY
user1 | user1 | <table ks.t1> | AUTHORIZE
(5 rows)
""")
else:
self.verify_output("LIST ALL PERMISSIONS OF user1", node1, """
username | resource | permission
----------+---------------+------------
user1 | <table ks.t1> | CREATE
user1 | <table ks.t1> | ALTER
user1 | <table ks.t1> | DROP
user1 | <table ks.t1> | SELECT
user1 | <table ks.t1> | MODIFY
user1 | <table ks.t1> | AUTHORIZE
(6 rows)
""")
def test_describe(self):
"""
@jira_ticket CASSANDRA-7814
"""
self.cluster.populate(1)
self.cluster.start()
node1, = self.cluster.nodelist()
self.execute(
cql="""
CREATE KEYSPACE test WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1};
CREATE TABLE test.users ( userid text PRIMARY KEY, firstname text, lastname text, age int);
CREATE INDEX myindex ON test.users (age);
CREATE INDEX "QuotedNameIndex" on test.users (firstName);
CREATE TABLE test.test (id int, col int, val text, PRIMARY KEY(id, col));
CREATE INDEX ON test.test (col);
CREATE INDEX ON test.test (val)
""")
# Describe keyspaces
output = self.execute(cql="DESCRIBE KEYSPACES")
assert "test" in output
assert "system" in output
# Describe keyspace
self.execute(cql="DESCRIBE KEYSPACE test", expected_output=self.get_keyspace_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE test", expected_output=self.get_keyspace_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE test2", expected_err="'test2' not found in keyspaces")
self.execute(cql="USE test; DESCRIBE KEYSPACE", expected_output=self.get_keyspace_output(), output_is_ordered=False)
# Describe table
self.execute(cql="DESCRIBE TABLE test.test", expected_output=self.get_test_table_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE TABLE test.users", expected_output=self.get_users_table_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE test.test", expected_output=self.get_test_table_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE test.users", expected_output=self.get_users_table_output(), output_is_ordered=False)
self.execute(cql="DESCRIBE test.users2", expected_err="'users2' not found in keyspace 'test'")
self.execute(cql="USE test; DESCRIBE TABLE test", expected_output=self.get_test_table_output(), output_is_ordered=False)
self.execute(cql="USE test; DESCRIBE TABLE users", expected_output=self.get_users_table_output(), output_is_ordered=False)
self.execute(cql="USE test; DESCRIBE test", expected_output=self.get_keyspace_output(), output_is_ordered=False)
self.execute(cql="USE test; DESCRIBE users", expected_output=self.get_users_table_output(), output_is_ordered=False)
self.execute(cql="USE test; DESCRIBE users2", expected_err="'users2' not found in keyspace 'test'")
# Describe index
self.execute(cql='DESCRIBE INDEX test.myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
self.execute(cql='DESCRIBE INDEX test.test_col_idx', expected_output=self.get_index_output('test_col_idx', 'test', 'test', 'col'))
self.execute(cql='DESCRIBE INDEX test.test_val_idx', expected_output=self.get_index_output('test_val_idx', 'test', 'test', 'val'))
self.execute(cql='DESCRIBE test.myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
self.execute(cql='DESCRIBE test.test_col_idx', expected_output=self.get_index_output('test_col_idx', 'test', 'test', 'col'))
self.execute(cql='DESCRIBE test.test_val_idx', expected_output=self.get_index_output('test_val_idx', 'test', 'test', 'val'))
self.execute(cql='DESCRIBE test.myindex2', expected_err="'myindex2' not found in keyspace 'test'")
self.execute(cql='USE test; DESCRIBE INDEX myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
self.execute(cql='USE test; DESCRIBE INDEX test_col_idx', expected_output=self.get_index_output('test_col_idx', 'test', 'test', 'col'))
self.execute(cql='USE test; DESCRIBE INDEX test_val_idx', expected_output=self.get_index_output('test_val_idx', 'test', 'test', 'val'))
self.execute(cql='USE test; DESCRIBE myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
self.execute(cql='USE test; DESCRIBE test_col_idx', expected_output=self.get_index_output('test_col_idx', 'test', 'test', 'col'))
self.execute(cql='USE test; DESCRIBE test_val_idx', expected_output=self.get_index_output('test_val_idx', 'test', 'test', 'val'))
self.execute(cql='USE test; DESCRIBE myindex2', expected_err="'myindex2' not found in keyspace 'test'")
# Drop table and recreate
self.execute(cql='DROP TABLE test.users')
self.execute(cql='DESCRIBE test.users', expected_err="'users' not found in keyspace 'test'")
self.execute(cql='DESCRIBE test.myindex', expected_err="'myindex' not found in keyspace 'test'")
self.execute(cql="""
CREATE TABLE test.users ( userid text PRIMARY KEY, firstname text, lastname text, age int);
CREATE INDEX myindex ON test.users (age);
CREATE INDEX "QuotedNameIndex" on test.users (firstname)
""")
self.execute(cql="DESCRIBE test.users", expected_output=self.get_users_table_output(), output_is_ordered=False)
self.execute(cql='DESCRIBE test.myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
# Drop index and recreate
self.execute(cql='DROP INDEX test.myindex')
self.execute(cql='DESCRIBE test.myindex', expected_err="'myindex' not found in keyspace 'test'")
self.execute(cql='CREATE INDEX myindex ON test.users (age)')
self.execute(cql='DESCRIBE INDEX test.myindex', expected_output=self.get_index_output('myindex', 'test', 'users', 'age'))
self.execute(cql='DROP INDEX test."QuotedNameIndex"')
self.execute(cql='DESCRIBE test."QuotedNameIndex"', expected_err="'QuotedNameIndex' not found in keyspace 'test'")
self.execute(cql='CREATE INDEX "QuotedNameIndex" ON test.users (firstname)')
self.execute(cql='DESCRIBE INDEX test."QuotedNameIndex"', expected_output=self.get_index_output('"QuotedNameIndex"', 'test', 'users', 'firstname'))
# Alter table. Renaming indexed columns is not allowed, and since 3.0 neither is dropping them
# Prior to 3.0 the index would have been automatically dropped, but now we need to explicitly do that.
self.execute(cql='DROP INDEX test.test_val_idx')
self.execute(cql='ALTER TABLE test.test DROP val')
self.execute(cql="DESCRIBE test.test", expected_output=self.get_test_table_output(has_val=False, has_val_idx=False), output_is_ordered=False)
self.execute(cql='DESCRIBE test.test_val_idx', expected_err="'test_val_idx' not found in keyspace 'test'")
self.execute(cql='ALTER TABLE test.test ADD val text')
self.execute(cql="DESCRIBE test.test", expected_output=self.get_test_table_output(has_val=True, has_val_idx=False), output_is_ordered=False)
self.execute(cql='DESCRIBE test.test_val_idx', expected_err="'test_val_idx' not found in keyspace 'test'")
def test_describe_describes_non_default_compaction_parameters(self):
self.cluster.populate(1)
self.cluster.start()
node, = self.cluster.nodelist()
session = self.patient_cql_connection(node)
create_ks(session, 'ks', 1)
session.execute("CREATE TABLE tab (key int PRIMARY KEY ) "
"WITH compaction = {'class': 'SizeTieredCompactionStrategy',"
"'min_threshold': 10, 'max_threshold': 100 }")
describe_cmd = 'DESCRIBE ks.tab'
stdout, _ = self.run_cqlsh(node, describe_cmd)
assert "'min_threshold': '10'" in stdout
assert "'max_threshold': '100'" in stdout
def test_describe_functions(self, fixture_dtest_setup_overrides):
"""Test DESCRIBE statements for functions and aggregate functions"""
self.cluster.populate(1)
self.cluster.start()
create_ks_statement = "CREATE KEYSPACE test WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}"
create_function_statement = """
CREATE FUNCTION test.some_function(arg int)
RETURNS NULL ON NULL INPUT
RETURNS int
LANGUAGE java
AS $$ return arg;
$$"""
create_aggregate_dependencies_statement = """
CREATE OR REPLACE FUNCTION test.average_state(state tuple<int,bigint>, val int)
CALLED ON NULL INPUT
RETURNS tuple<int,bigint>
LANGUAGE java
AS $$ if (val != null) {
state.setInt(0, state.getInt(0)+1);
state.setLong(1, state.getLong(1)+val.intValue());
}
return state;
$$;
CREATE OR REPLACE FUNCTION test.average_final (state tuple<int,bigint>)
CALLED ON NULL INPUT
RETURNS double
LANGUAGE java
AS $$
double r = 0;
if (state.getInt(0) == 0) return null;
r = state.getLong(1);
r /= state.getInt(0);
return Double.valueOf(r);
$$
"""
create_aggregate_statement = """
CREATE OR REPLACE AGGREGATE test.average(int)
SFUNC average_state
STYPE tuple<int,bigint>
FINALFUNC average_final
INITCOND (0, 0)
"""
# create keyspace, scalar function
self.execute(cql=create_ks_statement)
self.execute(cql=create_function_statement)
# describe scalar functions
if self.cluster.version() >= LooseVersion('3.0'):
expected_output = create_function_statement + ';'
else:
expected_output = create_function_statement
self.execute(cql='DESCRIBE FUNCTION test.some_function', expected_output=expected_output)
if self.cluster.version() >= LooseVersion('3.0'):
# create aggregate function
self.execute(cql=create_aggregate_dependencies_statement)
self.execute(cql=create_aggregate_statement)
# describe aggregate functions
self.execute(cql='DESCRIBE AGGREGATE test.average', expected_output=self.get_describe_aggregate_output())
def get_describe_aggregate_output(self):
if self.cluster.version() >= LooseVersion("4.0"):
return """
CREATE AGGREGATE test.average(int)
SFUNC average_state
STYPE tuple<int, bigint>
FINALFUNC average_final
INITCOND (0, 0);