Skip to content

fix(osi): skip empty expressions when picking a dialect expression#2413

Merged
goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/osi-pick-expression-empty-fallback
Jul 2, 2026
Merged

fix(osi): skip empty expressions when picking a dialect expression#2413
goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/osi-pick-expression-empty-fallback

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What

_pick_expression (OSI → MDL importer) resolves a SQL expression for a field/metric in priority order: preferred dialect → ANSI_SQL → first available. The membership checks used in by_dialect, so a present-but-empty expression for the preferred dialect (or for ANSI_SQL) counted as "found" and was returned verbatim — shadowing a real expression sitting in another dialect entry.

This skips blank expressions at every resolution tier and falls through to the first non-empty expression.

Why it's a bug

An empty string carries no SQL. When the preferred dialect entry is blank, the field is genuinely calculated elsewhere in the dialects list, but the importer would emit it as an empty/identity column — silently dropping the calculation.

Evidence

Before (unpatched) — new tests fail:

test_pick_expression_skips_empty_preferred_and_uses_ansi      FAILED
test_pick_expression_skips_empty_ansi_and_uses_first_nonempty FAILED
  assert "" == "SUM(x)"   /   assert "" == "[x]"

After (patched) — whole OSI suite green:

$ pytest tests/unit/test_osi.py
74 passed

Scope

  • core/wren/src/wren/osi.py_pick_expression skips empty entries per tier (1 change)
  • core/wren/tests/unit/test_osi.py — 2 new cases (empty-preferred→ANSI, empty-preferred+empty-ANSI→first non-empty)

Summary by CodeRabbit

  • Bug Fixes
    • Improved expression selection so blank dialect-specific values are skipped instead of being treated as valid results.
    • Prevented empty calculated fields from being emitted when the preferred or fallback dialect entry has no expression.
  • Tests
    • Added coverage for empty-expression handling and fallback behavior across dialects.

_pick_expression returned an empty string when the preferred dialect's
expression entry was present but blank, even though a later ANSI_SQL or
other dialect carried a real expression. An empty string carries no SQL,
so a calculated OSI field would be emitted as an empty/identity column.
Skip blank entries at each resolution tier (preferred -> ANSI_SQL ->
first non-empty).
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 39bb4817-69ec-4f09-a0f4-99605649f996

📥 Commits

Reviewing files that changed from the base of the PR and between 0c031d6 and 5d70451.

📒 Files selected for processing (2)
  • core/wren/src/wren/osi.py
  • core/wren/tests/unit/test_osi.py

Walkthrough

_pick_expression in osi.py is updated to treat empty-string expression values as absent rather than terminal, continuing to the next non-empty dialect entry. Two unit tests are added to cover the cases where the preferred dialect or both preferred and ANSI_SQL expressions are empty.

Changes

Empty expression fallback fix

Layer / File(s) Summary
_pick_expression fix and unit tests
core/wren/src/wren/osi.py, core/wren/tests/unit/test_osi.py
Empty-string expressions for the preferred dialect and ANSI_SQL are now skipped in favor of the next non-empty dialect entry. Two new tests assert this behavior for the preferred-dialect-empty and both-empty cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A blank expression tried to slip through,
But the rabbit said "Nope, that won't do!"
We skip past the empty, hop to the next,
A non-empty answer now passes the test. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: skipping empty dialect expressions when selecting an expression.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Bartok9 LGTM

@goldmedal goldmedal merged commit bcf78d1 into Canner:main Jul 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants