Skip to content

test(sqlrewrite): add unit tests for package sqlrewrite - #847

Merged
general-kroll-4-life merged 1 commit into
stackql:mainfrom
RyoKusnadi:feature/sqlrewrite-unit-tests
Oct 15, 2026
Merged

general-kroll-4-life merged 1 commit into
stackql:mainfrom
RyoKusnadi:feature/sqlrewrite-unit-tests

Conversation

@RyoKusnadi

Copy link
Copy Markdown
Contributor

The package internal/stackql/sqlrewrite had no unit tests. This PR adds them.

What I added:

One new file, sqlrewrite_test.go. It has one table-driven test for GenerateRewrittenSelectDML. Each row in the table is one case, and every case runs the same way. The test uses small fake objects in place of the real SQL system, config and tables, so it does not need a database.

The four cases:

  • No containers: the base counters are used, physical tables and materialized views are not counted, and the FROM, WHERE, qualifier and ORDER BY values reach ComposeSelectQuery unchanged.
  • Containers with a hoisted table (a table joined in the ON clause): the hoisted table's counters come first, a repeated alias is sent only once, and counters for the same table are kept together.
  • A hoisted table with no matching alias returns an error.
  • An error from ComposeSelectQuery is returned to the caller.

I did not change any production code.

Results: all tests pass, go test -cover ./internal/stackql/sqlrewrite/... shows 96.4% coverage (the issue asks for 85%), and golangci-lint v2.5.0 reports no issues for this package.

Note: another contributor took this issue in July. If they are still working on it, I'm happy to close this PR.

Fixes #268

@general-kroll-4-life

Copy link
Copy Markdown
Contributor

@RyoKusnadi thank you for your contribution!

@general-kroll-4-life
general-kroll-4-life merged commit 28755d4 into stackql:main Oct 15, 2026
31 checks passed
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.

Add unit testing to package sqlrewrite

2 participants