Skip to content
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

Full outer join not working #193

Closed
poofeg opened this issue Aug 16, 2022 · 1 comment · Fixed by #196
Closed

Full outer join not working #193

poofeg opened this issue Aug 16, 2022 · 1 comment · Fixed by #196

Comments

@poofeg
Copy link
Contributor

poofeg commented Aug 16, 2022

Describe the bug
The incorrect syntax of the full join is generated: "FULL LEFT OUTER JOIN".

To Reproduce

from clickhouse_sqlalchemy.drivers.base import clickhouse_dialect
from clickhouse_sqlalchemy.ext.declarative import ClickHouseDeclarativeMeta
from sqlalchemy import Integer, Column, select
from sqlalchemy.orm import declarative_base

Base = declarative_base(metaclass=ClickHouseDeclarativeMeta)


class Left(Base):
    __tablename__ = 'left_table'
    id = Column(Integer, primary_key=True)


class Right(Base):
    __tablename__ = 'right_table'
    id = Column(Integer, primary_key=True)


stmt = select(Left).outerjoin(Right, Left.id == Right.id, full=True)
compiled = stmt.compile(dialect=clickhouse_dialect)
print(compiled)
SELECT left_table.id 
FROM left_table FULL LEFT OUTER JOIN right_table ON left_table.id = right_table.id

Expected behavior

SELECT left_table.id 
FROM left_table FULL OUTER JOIN right_table ON left_table.id = right_table.id

Versions

  • clickhouse-sqlalchemy 0.2.1
  • Python 3.10.6
@poofeg
Copy link
Contributor Author

poofeg commented Aug 16, 2022

Temporary fix:

class FixedClickHouseSQLCompiler(ClickHouseSQLCompiler):
    def visit_join(self, join: Any, asfrom: bool = False, **kwargs: Any) -> str:
        return super().visit_join(join, asfrom, **kwargs).replace('FULL LEFT OUTER JOIN', 'FULL OUTER JOIN')


class FixedClickHouseDialect(ClickHouseDialect):
    statement_compiler = FixedClickHouseSQLCompiler


clickhouse_dialect = FixedClickHouseDialect()

poofeg added a commit to poofeg/clickhouse-sqlalchemy that referenced this issue Aug 27, 2022
xzkostyan added a commit that referenced this issue Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant