Skip to content

fix(r): cast a Snowflake semantic view variable to its declared type - #449

Draft
jat255 wants to merge 2 commits into
jat255/446-semantic-quoted-base-tablesfrom
jat255/447-semantic-variable-types
Draft

jat255 wants to merge 2 commits into
jat255/446-semantic-quoted-base-tablesfrom
jat255/447-semantic-variable-types

Conversation

@jat255

@jat255 jat255 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #447

This PR makes R cast a Snowflake semantic view's variables to the type the view declares. Snowflake refuses a value of another type, and Snowflake ODBC driver 4.x binds a number as text, so a parameterized metric call failed.

Details (agent-written)

semantic_parameters_from_spec() now keeps a Snowflake variable's declared type. A new helper in catalog-snowflake.R writes VARIABLES "MIN_TOTAL" => CAST(? AS NUMBER(10,2)), and both the metric query and the access probe use it. The type is put into SQL, so only a plain type name such as NUMBER(10,2) or TIMESTAMP_TZ is kept. Any other declaration leaves its variable with a bare placeholder, as before.

I cast to the declared type rather than to a fixed one: CAST(? AS NUMBER) also passes Snowflake's check, but it rounds 50.5 to 51.

Testing: the full R suite passes, with new cases for the cast and for a declared type that is not a plain name. On live Snowflake, every R Snowflake live test passes with this stack, including the three semantic view tests. I ran it with driver 4.0.0 on macOS only. CI on Linux may bind numbers differently, but the cast is correct for either.

Kata: whhh.

R changes

A Snowflake semantic view variable is now bound with a cast to the type the view declares (catalog-snowflake.R). A call such as call_metrics(..., arguments = '{"MIN_TOTAL": 50}') against a view that declares MIN_TOTAL NUMBER(10,2) used to fail with a type mismatch, and now returns the metric. Typed arguments for Snowflake gain an internal sql_type field. Databricks metric views are unchanged. NEWS has a bullet.

Snowflake requires a variable's value to match the type the view declares, and Snowflake ODBC driver 4.x binds a number as text, so a parameterized metric call failed. The declared type is now kept when the view is read, and the metric query and the access probe both write CAST(? AS <type>). A declared type that is not a plain type name is not spliced into SQL, and that variable keeps a bare placeholder.

Closes #447
@jat255 jat255 added bug Something isn't working r Affects the R implementation needs-manual-review Agent-created work that needs a human review labels Oct 22, 2026

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 r Affects the R implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant