Skip to content

Implement YDB specific concat #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,29 @@ def test_from_as_table(self, connection):
eq_(connection.execute(sa.select(table)).fetchall(), [(1,), (2,), (3,)])


class ConcatTest(fixtures.TablesTest):
@classmethod
def define_tables(cls, metadata):
Table(
"concat_func_test",
metadata,
Column("A", String),
Column("B", String),
sa.PrimaryKeyConstraint("A"),
schema=None,
test_needs_fk=True,
)

def test_concat_func(self, connection):
table = self.tables.concat_func_test

connection.execute(sa.insert(table).values([{"A": "A", "B": "B"}]))

stmt = select(func.concat(table.c.A, " ", table.c.B)).limit(1)

eq_(connection.scalar(stmt), "A B")


if not OLD_SA:
from sqlalchemy.testing.suite.test_types import NativeUUIDTest as _NativeUUIDTest

Expand Down
4 changes: 4 additions & 0 deletions ydb_sqlalchemy/sqlalchemy/compiler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ def visit_function(self, func, add_to_result_map=None, **kwargs):
+ [name]
) % {"expr": self.function_argspec(func, **kwargs)}

def visit_concat_func(self, func, **kwargs):
arg_sql = " || ".join(self.process(arg, **kwargs) for arg in func.clauses)
return arg_sql

def _is_bound_to_nullable_column(self, bind_name: str) -> bool:
if bind_name in self.column_keys and hasattr(self.compile_state, "dml_table"):
if bind_name in self.compile_state.dml_table.c:
Expand Down