Skip to content

Commit b1d3db2

Browse files
committed
Check for existence of shapely types; allow concurrent test runs on extended types
1 parent 48192ce commit b1d3db2

4 files changed

Lines changed: 45 additions & 23 deletions

File tree

singlestoredb/http/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ def convert_special_type(arg: Any) -> Any:
168168
dtype = type(arg)
169169
if has_numpy and dtype is np.ndarray:
170170
return arg.tobytes()
171-
if has_shapely and dtype is shapely.Point:
171+
if has_shapely and dtype is getattr(shapely, 'Point', None):
172172
return shapely.wkt.dumps(arg)
173-
if has_shapely and dtype is shapely.Polygon:
173+
if has_shapely and dtype is getattr(shapely, 'Polygon', None):
174174
return shapely.wkt.dumps(arg)
175-
if has_shapely and dtype is shapely.LineString:
175+
if has_shapely and dtype is getattr(shapely, 'LineString', None):
176176
return shapely.wkt.dumps(arg)
177177
if has_pygeos and dtype is pygeos.Geometry:
178178
return pygeos.io.to_wkt(arg)

singlestoredb/mysql/converters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,12 @@ def escape_shapely(value, mapping=None):
209209
"""Convert shapely geo objects."""
210210
return escape_str(shapely.wkt.dumps(value), mapping=mapping)
211211

212-
encoders[shapely.Polygon] = escape_shapely
213-
encoders[shapely.Point] = escape_shapely
214-
encoders[shapely.LineString] = escape_shapely
212+
if hasattr(shapely, 'Polygon'):
213+
encoders[shapely.Polygon] = escape_shapely
214+
if hasattr(shapely, 'Point'):
215+
encoders[shapely.Point] = escape_shapely
216+
if hasattr(shapely, 'LineString'):
217+
encoders[shapely.LineString] = escape_shapely
215218

216219
if has_pygeos:
217220

singlestoredb/tests/test.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ CREATE ROWSTORE TABLE IF NOT EXISTS `extended_types` (
355355
`id` INT(11),
356356
`geography` GEOGRAPHY,
357357
`geographypoint` GEOGRAPHYPOINT,
358-
`vectors` BLOB
358+
`vectors` BLOB,
359+
`testkey` LONGTEXT
359360
)
360361
COLLATE='utf8_unicode_ci';
361362

singlestoredb/tests/test_basics.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,20 @@ def test_wrap_exc(self):
500500
assert 'You have an error in your SQL syntax' in exc.errmsg, exc.errmsg
501501

502502
def test_extended_types(self):
503+
import uuid
504+
505+
key = str(uuid.uuid4())
506+
503507
# shapely data
504508
data = [
505-
(1, 'POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))', 'POINT(1.5 1.5)', [0.5, 0.6]),
506-
(2, 'POLYGON((5 1, 6 1, 6 2, 5 2, 5 1))', 'POINT(5.5 1.5)', [1.3, 2.5]),
507-
(3, 'POLYGON((5 5, 6 5, 6 6, 5 6, 5 5))', 'POINT(5.5 5.5)', [10.3, 11.1]),
508-
(4, 'POLYGON((1 5, 2 5, 2 6, 1 6, 1 5))', 'POINT(1.5 5.5)', [3.3, 3.4]),
509-
(5, 'POLYGON((3 3, 4 3, 4 4, 3 4, 3 3))', 'POINT(3.5 3.5)', [2.9, 9.5]),
509+
(1, 'POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))', 'POINT(1.5 1.5)', [0.5, 0.6], key),
510+
(2, 'POLYGON((5 1, 6 1, 6 2, 5 2, 5 1))', 'POINT(5.5 1.5)', [1.3, 2.5], key),
511+
(
512+
3, 'POLYGON((5 5, 6 5, 6 6, 5 6, 5 5))',
513+
'POINT(5.5 5.5)', [10.3, 11.1], key,
514+
),
515+
(4, 'POLYGON((1 5, 2 5, 2 6, 1 6, 1 5))', 'POINT(1.5 5.5)', [3.3, 3.4], key),
516+
(5, 'POLYGON((3 3, 4 3, 4 4, 3 4, 3 3))', 'POINT(3.5 3.5)', [2.9, 9.5], key),
510517
]
511518

512519
new_data = []
@@ -521,11 +528,14 @@ def test_extended_types(self):
521528
new_data.append(row)
522529

523530
self.cur.executemany(
524-
'INSERT INTO extended_types (id, geography, geographypoint, vectors) '
525-
'VALUES (%s, %s, %s, %s)', new_data,
531+
'INSERT INTO extended_types '
532+
'(id, geography, geographypoint, vectors, testkey) '
533+
'VALUES (%s, %s, %s, %s, %s)', new_data,
526534
)
527535

528-
self.cur.execute('SELECT * FROM extended_types ORDER BY id')
536+
self.cur.execute(
537+
'SELECT * FROM extended_types WHERE testkey = %s ORDER BY id', [key],
538+
)
529539

530540
for data_row, row in zip(new_data, self.cur):
531541
assert data_row[0] == row[0]
@@ -538,11 +548,14 @@ def test_extended_types(self):
538548

539549
# pygeos data
540550
data = [
541-
(6, 'POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))', 'POINT(1.5 1.5)', [0.5, 0.6]),
542-
(7, 'POLYGON((5 1, 6 1, 6 2, 5 2, 5 1))', 'POINT(5.5 1.5)', [1.3, 2.5]),
543-
(8, 'POLYGON((5 5, 6 5, 6 6, 5 6, 5 5))', 'POINT(5.5 5.5)', [10.3, 11.1]),
544-
(9, 'POLYGON((1 5, 2 5, 2 6, 1 6, 1 5))', 'POINT(1.5 5.5)', [3.3, 3.4]),
545-
(10, 'POLYGON((3 3, 4 3, 4 4, 3 4, 3 3))', 'POINT(3.5 3.5)', [2.9, 9.5]),
551+
(6, 'POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))', 'POINT(1.5 1.5)', [0.5, 0.6], key),
552+
(7, 'POLYGON((5 1, 6 1, 6 2, 5 2, 5 1))', 'POINT(5.5 1.5)', [1.3, 2.5], key),
553+
(
554+
8, 'POLYGON((5 5, 6 5, 6 6, 5 6, 5 5))',
555+
'POINT(5.5 5.5)', [10.3, 11.1], key,
556+
),
557+
(9, 'POLYGON((1 5, 2 5, 2 6, 1 6, 1 5))', 'POINT(1.5 5.5)', [3.3, 3.4], key),
558+
(10, 'POLYGON((3 3, 4 3, 4 4, 3 4, 3 3))', 'POINT(3.5 3.5)', [2.9, 9.5], key),
546559
]
547560

548561
new_data = []
@@ -557,11 +570,16 @@ def test_extended_types(self):
557570
new_data.append(row)
558571

559572
self.cur.executemany(
560-
'INSERT INTO extended_types (id, geography, geographypoint, vectors) '
561-
'VALUES (%s, %s, %s, %s)', new_data,
573+
'INSERT INTO extended_types '
574+
'(id, geography, geographypoint, vectors, testkey) '
575+
'VALUES (%s, %s, %s, %s, %s)', new_data,
562576
)
563577

564-
self.cur.execute('SELECT * FROM extended_types WHERE id >= 6 ORDER BY id')
578+
self.cur.execute(
579+
'SELECT * FROM extended_types WHERE id >= 6 and testkey = %s ORDER BY id', [
580+
key,
581+
],
582+
)
565583

566584
for data_row, row in zip(new_data, self.cur):
567585
assert data_row[0] == row[0]

0 commit comments

Comments
 (0)