Skip to content

Commit

Permalink
Merge pull request #229 from howbownotnow/master
Browse files Browse the repository at this point in the history
added ilike clause compilation
  • Loading branch information
xzkostyan committed Dec 21, 2022
2 parents 7cd1db9 + 1571464 commit 76af10a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions clickhouse_sqlalchemy/drivers/compilers/sqlcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,18 @@ def visit_not_regexp_match_op_binary(self, binary, operator, **kw):
operator,
**kw
)

def visit_ilike_case_insensitive_operand(self, element, **kw):
return element.element._compiler_dispatch(self, **kw)

def visit_ilike_op_binary(self, binary, operator, **kw):
return "%s ILIKE %s" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw)
)

def visit_not_ilike_op_binary(self, binary, operator, **kw):
return "%s NOT ILIKE %s" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw)
)
35 changes: 35 additions & 0 deletions tests/sql/test_ilike.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from sqlalchemy import Column
from clickhouse_sqlalchemy import types, Table

from tests.testcase import BaseTestCase


class ILike(BaseTestCase):
table = Table(
't1',
BaseTestCase.metadata(),
Column('x', types.Int32, primary_key=True),
Column('y', types.String)
)

def test_ilike(self):
query = (
self.session.query(self.table.c.x)
.where(self.table.c.y.ilike('y'))
)

self.assertEqual(
self.compile(query, literal_binds=True),
"SELECT t1.x AS t1_x FROM t1 WHERE t1.y ILIKE 'y'"
)

def test_not_ilike(self):
query = (
self.session.query(self.table.c.x)
.where(self.table.c.y.not_ilike('y'))
)

self.assertEqual(
self.compile(query, literal_binds=True),
"SELECT t1.x AS t1_x FROM t1 WHERE t1.y NOT ILIKE 'y'"
)

0 comments on commit 76af10a

Please sign in to comment.