Skip to content

refactor: turn Dialect into a per-driver interface#9149

Merged
k-anshul merged 17 commits into
mainfrom
namanmahor/plat-449-refactor-the-dialects-into-the-drivers
Apr 21, 2026
Merged

refactor: turn Dialect into a per-driver interface#9149
k-anshul merged 17 commits into
mainfrom
namanmahor/plat-449-refactor-the-dialects-into-the-drivers

Conversation

@NamanMahor
Copy link
Copy Markdown
Contributor

@NamanMahor NamanMahor commented Mar 31, 2026

Replace the monolithic Dialect int enum of switch-statement logic in runtime/drivers/olap.go with a Dialect interface. Move shared default implementations into a new BaseDialect and have each OLAP driver own its dialect implementation in a dedicated dialect.go file.

  • runtime/drivers/dialect.go: replace Dialect int/constants/methods with a Dialect interface; add DialectName* string constants for comparisons, add BaseDialect
  • 11 new runtime/drivers/*/dialect.go files, one per driver
  • All callers updated to use Dialect().String() against DialectName* constants instead of comparing int values

Closes PLAT-449: Refactor the dialects into the drivers

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

NamanMahor and others added 8 commits March 31, 2026 17:57
Replace the monolithic `Dialect int` enum and its ~900 lines of
switch-statement logic in `runtime/drivers/olap.go` with a `Dialect`
interface. Move shared default implementations into a new
`runtime/pkg/sqldialect` package (Base struct + helpers), and have each
OLAP driver own its dialect implementation in a dedicated `dialect.go`
file.

- `runtime/drivers/olap.go`: replace `Dialect int`/constants/methods
  with a `Dialect` interface; add `DialectName*` string constants for
  comparisons
- `runtime/pkg/sqldialect/base.go`: `Base` struct with virtual dispatch
  via a local `Dispatcher` interface (avoids circular import)
- `runtime/pkg/sqldialect/helpers.go`: `DruidTimeFloorSpecifier`,
  `TempName`, `CheckTypeCompatibility`
- 11 new `runtime/drivers/*/dialect.go` files, one per driver
- All callers updated to use `Dialect().String()` against `DialectName*`
  constants instead of comparing int values

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@NamanMahor NamanMahor requested review from begelundmuller and k-anshul and removed request for begelundmuller April 9, 2026 05:35
Comment thread runtime/drivers/dialect.go
Comment thread runtime/drivers/snowflake/snowflake.go Outdated
@begelundmuller begelundmuller removed their request for review April 15, 2026 15:12
Comment thread cli/cmd/project/tables.go Outdated
Comment thread runtime/drivers/clickhouse/crud.go
Comment thread runtime/drivers/druid/druid.go Outdated
// For views it returns columns: [View, Create View, character_set_client, collation_connection].
// We extract the DDL by column name to avoid depending on column order or count.
rows, err := db.QueryxContext(ctx, fmt.Sprintf("SHOW CREATE TABLE %s", drivers.DialectMySQL.EscapeTable(table.Database, table.DatabaseSchema, table.Name)))
rows, err := db.QueryxContext(ctx, fmt.Sprintf("SHOW CREATE TABLE %s", c.Dialect().EscapeTable(table.Database, table.DatabaseSchema, table.Name)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Directly use DialectMySQL

Comment thread cli/cmd/project/tables.go
// Get row count using SQL query
var rowCount string
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", drivers.DialectDuckDB.EscapeIdentifier(table.Name))
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", escapeIdentifier(table.Name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually on reflection this will fail for BigQuery and possible Snowflake but lets take it up separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread runtime/drivers/dialect.go Outdated
Comment thread runtime/drivers/dialect.go Outdated
Comment thread runtime/metricsview/executor/executor.go
@k-anshul k-anshul removed the request for review from begelundmuller April 21, 2026 05:58
@k-anshul k-anshul dismissed begelundmuller’s stale review April 21, 2026 05:58

Already approved offline

@k-anshul k-anshul merged commit b2c804e into main Apr 21, 2026
13 checks passed
@k-anshul k-anshul deleted the namanmahor/plat-449-refactor-the-dialects-into-the-drivers branch April 21, 2026 05:58
pjain1 pushed a commit that referenced this pull request Apr 30, 2026
* refactor: turn `Dialect` into a per-driver interface

Replace the monolithic `Dialect int` enum and its ~900 lines of
switch-statement logic in `runtime/drivers/olap.go` with a `Dialect`
interface. Move shared default implementations into a new
`runtime/pkg/sqldialect` package (Base struct + helpers), and have each
OLAP driver own its dialect implementation in a dedicated `dialect.go`
file.

- `runtime/drivers/olap.go`: replace `Dialect int`/constants/methods
  with a `Dialect` interface; add `DialectName*` string constants for
  comparisons
- `runtime/pkg/sqldialect/base.go`: `Base` struct with virtual dispatch
  via a local `Dispatcher` interface (avoids circular import)
- `runtime/pkg/sqldialect/helpers.go`: `DruidTimeFloorSpecifier`,
  `TempName`, `CheckTypeCompatibility`
- 11 new `runtime/drivers/*/dialect.go` files, one per driver
- All callers updated to use `Dialect().String()` against `DialectName*`
  constants instead of comparing int values

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* move dialect to olap.go

* more refactoring

* self review

* self review

* self review 3

* self review 4

* lint

* move dialect to dialect.go from olap.go

* review comments

* review comments

* review comment

* review comments

* review comment

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants