Skip to content

Commit 3a6ba36

Browse files
jtgrabowskijacek-lewandowski
authored andcommitted
STAR-254: add DateRange and Geo tests (#9)
* STAR-254 add tests for geo and date range types (cherry picked from commit d15a708) (cherry picked from commit 5bd412f)
1 parent ee9b612 commit 3a6ba36

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

cqlsh_tests/test_cqlsh_copy.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,3 +3336,79 @@ def _test_invalid_data_for_maps():
33363336
_test_invalid_data_for_sets()
33373337
_test_invalid_data_for_lists()
33383338
_test_invalid_data_for_maps()
3339+
3340+
@since('4.0')
3341+
def test_geotypes_copy(self):
3342+
"""
3343+
Tests whether cqlsh COPY properly handles geo types with empty and null values.
3344+
3345+
@since 4.0.0
3346+
3347+
Steps:
3348+
* insert several geoTypes with null and empty values among them into a table
3349+
* cqlsh copy contents to .csv file and save them in a list
3350+
* wipe the table comletely of all data
3351+
* cqlsh copy contents from .csv back into the table
3352+
* get the contents of the table into a list
3353+
* assert the pre wiped data is the same as the newly copied data
3354+
:return
3355+
"""
3356+
self.prepare()
3357+
3358+
self.session.execute("create table geo (k int primary key, point 'PointType', line 'LineStringType', poly 'PolygonType');")
3359+
self.session.execute("insert into geo (k, point, line, poly) VALUES (0, 'point(1.2 3.4)', 'linestring(1.0 1.1, 2.0 2.1, 3.0 3.1)', 'POLYGON ((10.1 10.0, 110.0 10.0, 110.0 110.0, 10.0 110.0, 10.0 10.0), (20.0 20.0, 20.0 30.0, 30.0 30.0, 30.0 20.0, 20.0 20.0))');")
3360+
self.session.execute("insert into geo (k, point, line, poly) VALUES (2, 'point(1.2 3.4)', 'linestring EMPTY', 'POLYGON EMPTY');")
3361+
self.session.execute("insert into geo (k) VALUES (1);")
3362+
3363+
# make sure data is inserted
3364+
data_actual = rows_to_list(self.session.execute("select * from geo;"))
3365+
assert len(data_actual) == 3
3366+
3367+
# dump data to CSV and truncate
3368+
tempfile = self.get_temp_file()
3369+
self.run_cqlsh(cmds="COPY ks.geo TO '{name}'".format(name=tempfile.name))
3370+
self.run_cqlsh(cmds="truncate ks.geo;")
3371+
3372+
# import data back
3373+
self.run_cqlsh(cmds="COPY ks.geo FROM '{name}'".format(name=tempfile.name))
3374+
data_copy = rows_to_list(self.session.execute("select * from geo;"))
3375+
3376+
assert data_actual == data_copy
3377+
3378+
@since("4.0")
3379+
def test_date_range_copy(self):
3380+
"""
3381+
DateRangeTests.test_copy_command
3382+
3383+
Tests whether cqlsh COPY properly handles date_range types, including null values.
3384+
@note we cannot insert empty value ('') as it is not presented as null in cqlsh but it is in COPY
3385+
"""
3386+
self.prepare()
3387+
3388+
self.session.execute("create table incomes (org text, period 'DateRangeType', incomes int, ver 'DateRangeType', primary key (org, period));")
3389+
# insert some data
3390+
self.session.execute("insert into incomes(org, period, incomes) values ('A','2014', 20140);")
3391+
self.session.execute("insert into incomes(org, period, incomes) values ('A','2015', 201500);")
3392+
self.session.execute("insert into incomes(org, period, incomes) values ('A','[2016-01-01 TO 2016-06-30]', 1007);")
3393+
self.session.execute("insert into incomes(org, period, incomes) values ('B','[2017-02-12 12:30:07 TO 2017-02-17 13:39:43.789]', 777);")
3394+
self.session.execute("insert into incomes(org, period, incomes, ver) values ('X','2011', 0, null);")
3395+
self.session.execute("insert into incomes(org, period, incomes) values ('C','*', 996);")
3396+
self.session.execute("insert into incomes(org, period, incomes) values ('C','[* TO *]', 997);")
3397+
self.session.execute("insert into incomes(org, period, incomes) values ('C','[* TO 2015-01]', 998);")
3398+
self.session.execute("insert into incomes(org, period, incomes) values ('C','[2015-01 TO *]', 999);")
3399+
3400+
# make sure data is inserted
3401+
data_actual = rows_to_list(self.session.execute("select * from incomes;"))
3402+
assert len(data_actual) == 9
3403+
3404+
# dump data to CSV and truncate
3405+
tempfile = self.get_temp_file()
3406+
self.run_cqlsh(cmds="COPY ks.incomes TO '{name}'".format(name=tempfile.name))
3407+
self.run_cqlsh(cmds="truncate ks.incomes;")
3408+
3409+
# import data back
3410+
self.run_cqlsh(cmds="COPY ks.incomes FROM '{name}'".format(name=tempfile.name))
3411+
data_copy = rows_to_list(self.session.execute("select * from incomes;"))
3412+
3413+
assert data_actual == data_copy
3414+

cqlsh_tests/test_cqlsh_types.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import logging
2+
import pytest
3+
4+
from dtest import Tester, create_ks
5+
6+
logger = logging.getLogger(__name__)
7+
since = pytest.mark.since
8+
9+
10+
@since("4.0")
11+
class TestCqlshTypes(Tester):
12+
13+
def prepare(self, workload=None):
14+
if not self.cluster.nodelist():
15+
self.allow_log_errors = True
16+
self.cluster.populate(1)
17+
if workload is not None:
18+
for node in self.cluster.nodelist():
19+
node.set_workload(workload)
20+
logger.debug('About to start cluster')
21+
self.cluster.start()
22+
logger.debug('Cluster started')
23+
for node in self.cluster.nodelist():
24+
node.watch_log_for('Starting listening for CQL clients', timeout=60)
25+
self.cluster.nodelist()[0].watch_log_for('Created default superuser')
26+
self.node = self.cluster.nodelist()[0]
27+
28+
conn = self.patient_cql_connection(self.node)
29+
create_ks(conn, 'ks', 1)
30+
31+
logger.debug('prepare completed')
32+
33+
def test_point(self):
34+
self.prepare()
35+
36+
expected = 'POINT (1.2 2.3)'
37+
self.node.run_cqlsh("CREATE TABLE ks.point_tbl (k INT PRIMARY KEY, point 'PointType');")
38+
self.node.run_cqlsh("INSERT INTO ks.point_tbl (k, point) VALUES (1, '{}')".format(expected))
39+
result = self.node.run_cqlsh("SELECT * FROM ks.point_tbl;")
40+
assert expected in result[0], result
41+
42+
def test_linestring(self):
43+
self.prepare()
44+
45+
expected = 'LINESTRING (30.0 10.0, 10.0 30.0, 40.0 40.0)'
46+
self.node.run_cqlsh("CREATE TABLE ks.line_tbl (k INT PRIMARY KEY, linestring 'LineStringType');")
47+
self.node.run_cqlsh("INSERT INTO ks.line_tbl (k, linestring) VALUES (1, '{}')".format(expected))
48+
result = self.node.run_cqlsh("SELECT * FROM ks.line_tbl;")
49+
assert expected in result[0], result
50+
51+
def test_polygon(self):
52+
self.prepare()
53+
54+
expected = 'POLYGON ((30.0 10.0, 40.0 40.0, 20.0 40.0, 10.0 20.0, 30.0 10.0))'
55+
self.node.run_cqlsh("CREATE TABLE ks.polygon_tbl (k INT PRIMARY KEY, polygon 'PolygonType');")
56+
self.node.run_cqlsh("INSERT INTO ks.polygon_tbl (k, polygon) VALUES (1, '{}')".format(expected))
57+
result = self.node.run_cqlsh("SELECT * FROM ks.polygon_tbl;")
58+
assert expected in result[0], result
59+
60+
def test_date_range(self):
61+
self.prepare()
62+
63+
expected = '[2015-01 TO *]'
64+
self.node.run_cqlsh("CREATE TABLE ks.date_range_tbl (k INT PRIMARY KEY, date_range_tbl 'DateRangeType');")
65+
self.node.run_cqlsh("INSERT INTO ks.date_range_tbl (k, date_range_tbl) VALUES (1, '{}')".format(expected))
66+
result = self.node.run_cqlsh("SELECT * FROM ks.date_range_tbl;")
67+
assert expected in result[0], result

0 commit comments

Comments
 (0)