Skip to content

Commit 54aa19e

Browse files
author
Ilya Gurov
authored
feat: raise exceptions for ESCAPE keyword (#64)
1 parent 9581aea commit 54aa19e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

+11
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ def visit_empty_set_expr(self, type_):
137137
_type_map_inv[type(type_[0])]
138138
)
139139

140+
def visit_like_op_binary(self, binary, operator, **kw):
141+
"""Build a LIKE clause."""
142+
if binary.modifiers.get("escape", None):
143+
raise NotImplementedError("ESCAPE keyword is not supported by Spanner")
144+
145+
# TODO: use ternary here, not "and"/ "or"
146+
return "%s LIKE %s" % (
147+
binary.left._compiler_dispatch(self, **kw),
148+
binary.right._compiler_dispatch(self, **kw),
149+
)
150+
140151
def render_literal_value(self, value, type_):
141152
"""Render the value of a bind parameter as a quoted literal.
142153

test/test_suite.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1326,42 +1326,48 @@ def test_enotation_decimal(self):
13261326

13271327

13281328
class LikeFunctionsTest(_LikeFunctionsTest):
1329-
@pytest.mark.skip("Spanner does not support ESCAPE")
1329+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13301330
def test_contains_autoescape(self):
13311331
pass
13321332

1333-
@pytest.mark.skip("Spanner does not support ESCAPE")
1333+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13341334
def test_contains_autoescape_escape(self):
13351335
pass
13361336

1337-
@pytest.mark.skip("Spanner does not support ESCAPE")
1337+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13381338
def test_contains_escape(self):
13391339
pass
13401340

1341-
@pytest.mark.skip("Spanner does not support ESCAPE")
1341+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13421342
def test_endswith_autoescape(self):
13431343
pass
13441344

1345-
@pytest.mark.skip("Spanner does not support ESCAPE")
1345+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13461346
def test_endswith_escape(self):
13471347
pass
13481348

1349-
@pytest.mark.skip("Spanner does not support ESCAPE")
1349+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13501350
def test_endswith_autoescape_escape(self):
13511351
pass
13521352

1353-
@pytest.mark.skip("Spanner does not support ESCAPE")
1353+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13541354
def test_startswith_autoescape(self):
13551355
pass
13561356

1357-
@pytest.mark.skip("Spanner does not support ESCAPE")
1357+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13581358
def test_startswith_escape(self):
13591359
pass
13601360

1361-
@pytest.mark.skip("Spanner does not support ESCAPE")
1361+
@pytest.mark.skip("Spanner doesn't support LIKE ESCAPE clause")
13621362
def test_startswith_autoescape_escape(self):
13631363
pass
13641364

1365+
def test_escape_keyword_raises(self):
1366+
"""Check that ESCAPE keyword causes an exception when used."""
1367+
with pytest.raises(NotImplementedError):
1368+
col = self.tables.some_table.c.data
1369+
self._test(col.contains("b##cde", escape="#"), {7})
1370+
13651371

13661372
@pytest.mark.skip("Spanner doesn't support quotes in table names.")
13671373
class QuotedNameArgumentTest(_QuotedNameArgumentTest):

0 commit comments

Comments
 (0)