@@ -3336,3 +3336,79 @@ def _test_invalid_data_for_maps():
3336
3336
_test_invalid_data_for_sets ()
3337
3337
_test_invalid_data_for_lists ()
3338
3338
_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
+
0 commit comments