Skip to content

Commit 68d12fc

Browse files
committed
Implement YDB specific concat
1 parent 1ce95c3 commit 68d12fc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/test_suite.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,29 @@ def test_from_as_table(self, connection):
546546
eq_(connection.execute(sa.select(table)).fetchall(), [(1,), (2,), (3,)])
547547

548548

549+
class ConcatTest(fixtures.TablesTest):
550+
@classmethod
551+
def define_tables(cls, metadata):
552+
Table(
553+
"concat_func_test",
554+
metadata,
555+
Column("A", String),
556+
Column("B", String),
557+
sa.PrimaryKeyConstraint("A"),
558+
schema=None,
559+
test_needs_fk=True,
560+
)
561+
562+
def test_concat_func(self, connection):
563+
table = self.tables.concat_func_test
564+
565+
connection.execute(sa.insert(table).values([{"A": "A", "B": "B"}]))
566+
567+
stmt = select(func.concat(table.c.A, " ", table.c.B)).limit(1)
568+
569+
eq_(connection.scalar(stmt), "A B")
570+
571+
549572
if not OLD_SA:
550573
from sqlalchemy.testing.suite.test_types import NativeUUIDTest as _NativeUUIDTest
551574

ydb_sqlalchemy/sqlalchemy/compiler/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ def visit_function(self, func, add_to_result_map=None, **kwargs):
307307
+ [name]
308308
) % {"expr": self.function_argspec(func, **kwargs)}
309309

310+
def visit_concat_func(self, func, **kwargs):
311+
arg_sql = " || ".join(self.process(arg, **kwargs) for arg in func.clauses)
312+
return arg_sql
313+
310314
def _is_bound_to_nullable_column(self, bind_name: str) -> bool:
311315
if bind_name in self.column_keys and hasattr(self.compile_state, "dml_table"):
312316
if bind_name in self.compile_state.dml_table.c:

0 commit comments

Comments
 (0)