Skip to content

SQLAlchemy core improvements#688

Open
joe-clickhouse wants to merge 5 commits intomainfrom
joe/sqlalchemy-improvements
Open

SQLAlchemy core improvements#688
joe-clickhouse wants to merge 5 commits intomainfrom
joe/sqlalchemy-improvements

Conversation

@joe-clickhouse
Copy link
Contributor

@joe-clickhouse joe-clickhouse commented Mar 24, 2026

Summary

This PR introduces and fixes a number of core SQLAlchemy core issues.

  • Comprehensive JOIN support: New ch_join() helper and ClickHouseJoin class now supports all ClickHouse strictness modifiers (ALL, ANY, SEMI, ANTI, ASOF), GLOBAL distribution modifier, and explicit CROSS JOIN. Use with select_from() to generate ClickHouse-specific join syntax like GLOBAL ALL LEFT OUTER JOIN.
    Closes SQLAlchemy: JOIN modifiers (ALL/ANY/ASOF, GLOBAL) #635

  • Multi-column ARRAY JOIN: array_join() now accepts a list of columns with optional per-column aliases for parallel array expansion. Generates ARRAY JOIN col1 AS a, col2 AS b, col3 AS c. Single-column usage is unchanged and backward compatible, including direct ArrayJoin constructor calls.
    Closes SQLAlchemy: ARRAY JOIN with multiple columns #633

  • JOIN USING support: ch_join() now supports using=["col1", "col2"] to generate USING (col1, col2) instead of ON. This is needed for FULL OUTER JOIN where USING merges the join column correctly while ON produces default values (0, '') for unmatched sides. This also includes proper cache key differentiation.
    Closes SQLAlchemy: add support for JOIN USING syntax #636

  • FINAL/SAMPLE fix: Fixed .final() and .sample() silently overwriting each other when chained on the same select.
    Closes SQLAlchemy: .final() and .sample() silently overwrite each other when chained #658

  • VALUES compiler fix: Fixed visit_values to use ClickHouse's VALUES(structure, tuples) table function syntax instead of standard SQL rendering.
    Closes SQLAlchemy: VALUES function is constructed incorrectly #681

SQAlchemt versions

It's worth noting that SQLAlchemy 1.4 support is still required for Superset integration. However, a small number of features require SQLAlchemy 2.x. E.g. Values.cte() and certain literal-rendering behaviors, but otherwise both 1.4 and 2.x are still considered supported.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@joe-clickhouse joe-clickhouse changed the title SQA core improvements SQLAlchemy core improvements Mar 24, 2026
@joe-clickhouse
Copy link
Contributor Author

@claude[agent] review this PR.

@Claude
Copy link

Claude AI commented Mar 24, 2026

@claude[agent] review this PR.

Code review completed. This is a high-quality PR with comprehensive JOIN support, multi-column ARRAY JOIN, USING syntax, and proper FINAL/SAMPLE fixes.

Strengths:

  • Thorough validation and error handling
  • Excellent test coverage (unit + integration)
  • Proper SQLAlchemy 1.4/2.x compatibility
  • Well-documented changes

Minor suggestions:

  1. Export sample function in __all__ for consistency with final
  2. Consider restoring detailed docstring for sample() parameter descriptions

Recommendation: APPROVE - Code is production-ready, suggestions are non-blocking improvements for developer experience.

@Claude Claude AI changed the title SQLAlchemy core improvements Addressing PR comments Mar 24, 2026
@joe-clickhouse joe-clickhouse changed the title Addressing PR comments SQLAlchemy core improvements Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants