Skip to content

feat: SQL translator with ClickHouse dialect#1

Merged
khvn26 merged 8 commits into
mainfrom
initial-scaffold
May 19, 2026
Merged

feat: SQL translator with ClickHouse dialect#1
khvn26 merged 8 commits into
mainfrom
initial-scaffold

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented May 7, 2026

Contributes to Flagsmith/flagsmith#5663.

Scaffold, translator, Dialect protocol, and the first dialect (ClickHouse) for flagsmith-sql-flag-engine — sibling to flagsmith-flag-engine (Python) and flagsmith-rust-flag-engine (Rust). Translates SegmentContext predicate trees into SQL WHERE expressions.

Public API

from flagsmith_sql_flag_engine import TranslateContext, translate_segment
from flagsmith_sql_flag_engine.dialects import ClickHouseDialect

ctx = TranslateContext(
    evaluation_context={"environment": {"key": "n9fbf...3ngWhb", "name": "Production"}},
    dialect=ClickHouseDialect(),
)
where_expr = translate_segment(segment, ctx)

EnvironmentContext.key lands directly as the environment_id literal in emitted SQL — no separate integer PK.

What's included

  • uv-managed Python package, src/ layout, py.typed
  • Dialect protocol with ClickHouseDialect (native JSON column, typed subcolumns)
  • Engine-parity harness running against a docker-compose ClickHouse — no external credentials required
  • engine-test-data as a git submodule pinned to v3.7.0
  • 56 translator unit tests + 599 / 3 xfailed engine-parity tests
  • mypy strict, ruff, 100% line + branch coverage gate via Cobertura
  • Renovate, CODEOWNERS

SnowflakeDialect follows in #9.

Operator coverage

Operator Translatable Notes
EQUAL, NOT_EQUAL, IN yes
IS_SET, IS_NOT_SET yes trait subcolumn IS NOT NULL / IS NULL
CONTAINS, NOT_CONTAINS yes
GREATER_THAN, LESS_THAN plus _INCLUSIVE yes
MODULO yes
PERCENTAGE_SPLIT yes inlined MD5-mod-9999; ~0.005% diverge on hash==9998
REGEX partial dialect-flavour gated; unsupported patterns → caller fallback
:semver-marked comparators yes major.minor.patch only; ignores prerelease

@khvn26 khvn26 changed the title Initial package scaffold feat: Implement Snowlake dialect May 7, 2026
@khvn26 khvn26 changed the title feat: Implement Snowlake dialect feat: Implement SQL engine, Snowlake dialect May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

File Coverage Missing
All files 100%

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against 4b87f0d

@khvn26 khvn26 requested review from a team, Zaimwa9 and gagantrivedi and removed request for a team and Zaimwa9 May 9, 2026 20:58
@gagantrivedi gagantrivedi removed their assignment May 15, 2026
@gagantrivedi gagantrivedi removed their request for review May 15, 2026 07:52
@khvn26 khvn26 requested a review from emyller May 15, 2026 17:55
khvn26 added 4 commits May 15, 2026 19:23
Adds the repo plumbing the rest of the branch builds on:

  - pyproject (uv build backend, mypy strict, 100% branch coverage gate,
    clickhouse-connect dev dep)
  - Makefile (install / lint / typecheck / test)
  - pre-commit (ruff, uv-lock, flagsmith-lint-tests, local mypy)
  - GitHub Actions CI: lint → typecheck → ClickHouse docker-compose →
    test → cobertura coverage gate
  - engine-test-data submodule pinned at v3.7.0
  - docker-compose for the ClickHouse parity harness
  - CODEOWNERS, renovate, .python-version, gitignore additions
  - py.typed marker and empty package skeleton

beep boop
beep boop
@khvn26 khvn26 force-pushed the initial-scaffold branch from 6adc186 to 377aa0e Compare May 15, 2026 19:03
@khvn26 khvn26 changed the title feat: Implement SQL engine, Snowlake dialect feat: SQL translator with ClickHouse dialect May 15, 2026
Copy link
Copy Markdown

@emyller emyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read the docs, and glanced through tests, and all the code. Honestly trusting engine test and coverage results more than my thoroughness in reviewing this, but also honestly this looks good to experiment with.

Comment thread README.md
@khvn26 khvn26 merged commit 3a6a175 into main May 19, 2026
2 checks passed
@emyller emyller deleted the initial-scaffold branch May 19, 2026 17:01
@matthewelwell matthewelwell linked an issue May 20, 2026 that may be closed by this pull request
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 this pull request may close these issues.

ClickHouse dialect

3 participants