Skip to content

fix: keep a division's operands grouped on Snowflake and Databricks - #442

Draft
jat255 wants to merge 1 commit into
jat255/whhh-live-warehouse-rfrom
jat255/439-divisor-parentheses
Draft

jat255 wants to merge 1 commit into
jat255/whhh-live-warehouse-rfrom
jat255/439-divisor-parentheses

Conversation

@jat255

@jat255 jat255 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #439

This PR fixes the Snowflake and Databricks SQL for a division, which dropped the parentheses around a compound operand. amount / (ratio * 2) compiled to "amount" / "ratio" * 2, so the query ran without an error and returned a wrong value.

Details (agent-written)

The guarded division now builds its quotient with the same precedence rule as every other infix operator, in the Python emitter and the R emitter. The zero guards keep the bare operands, because a comparison binds more loosely than arithmetic.

The shared warehouse fixture now pins the quotient of the corpus definition negative quotient for both targets. I did not add a corpus definition with a product divisor. It goes through the same code, and a new corpus entry means regenerating definitions.json from data-dict and updating its hand-maintained sections and the counts that tests pin.

Testing: the full Python and R suites pass. On live Snowflake, with the rest of this stack, every corpus definition returns the same values as DuckDB. Databricks is not verified, because no workspace is available yet.

Kata: whhh (the live warehouse work that found this).

R changes

The R SQL emitter for Snowflake and Databricks now keeps the parentheses around a compound numerator or divisor (definition-emit-sql.R). A definition such as amount / (ratio * 2) or (a + b) / c used to compile to SQL that computed a different value, and now computes the value that data-dict defines. The DuckDB output does not change. NEWS has a bullet.

@jat255 jat255 added bug Something isn't working needs-manual-review Agent-created work that needs a human review labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Preview root: https://posit-dev.github.io/commons/pr-442/

Python site preview: https://posit-dev.github.io/commons/pr-442/py/

Built from the latest commit on this branch. The R links in it point at the published R site, which no pull request rebuilds.

The guarded division rendered both operands at the lowest precedence and joined them with /, so amount / (ratio * 2) became "amount" / "ratio" * 2. The quotient now wraps each operand at division's precedence, as every other infix does. The zero guards keep the bare operands, since a comparison binds looser than arithmetic.

The shared warehouse fixture now pins the quotient of the corpus's negative quotient for both targets.

Closes #439
@jat255
jat255 force-pushed the jat255/439-divisor-parentheses branch from 6806780 to 44d353a Compare October 22, 2026 02:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-manual-review Agent-created work that needs a human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant