Add query_options model config for SQL Server OPTION clauses (#613).#674
Add query_options model config for SQL Server OPTION clauses (#613).#674Benjamin-Knight wants to merge 5 commits into
Conversation
…t#613). Supports a dict form (allowlisted hints; MAX_GRANT_PERCENT / MIN_GRANT_PERCENT use `=` syntax) and a query_options_raw escape hatch. Honoured on table, incremental (delete+insert, merge, microbatch), snapshot, and unit_test materializations; view raises a compiler error if set. apply_label() is preserved as a backward-compat alias emitting only the LABEL hint.
| {#- Backward-compat alias for the pre-1.10 macro. Emits only the LABEL hint | ||
| and ignores query_options / query_options_raw. New adapter code should | ||
| call get_query_options() directly. | ||
|
|
||
| Note: this preserves non-breaking *consumption* of apply_label (user | ||
| macros calling `{{ apply_label() }}` still resolve), but does NOT | ||
| preserve non-breaking *override*: adapter macros no longer call | ||
| apply_label internally, so a project that overrides apply_label in its | ||
| own macros directory will find that override has no effect on adapter | ||
| behaviour. To customise the OPTION clause emitted by adapter macros, | ||
| override get_query_options instead. -#} |
There was a problem hiding this comment.
Please add this deprecation on the changelog so we don't forget to publish it on release or check if we can avoid it as a standard execution path, this can reasonably fail with a targeted compiler error and instruct them to override get_query_options() instead.
Should we make something like this?:
- Make get_query_options() compose with apply_label() so existing apply_label() overrides still affect generated SQL.
- Add a test where a project overrides apply_label() and verifies table/incremental SQL still includes the custom label.
- Document get_query_options() as the new extension point for full query-hint customization.
- Keep apply_label() supported for at least one release cycle?
There was a problem hiding this comment.
I'm not sure how we could keep apply label support. If anyone was using apply label overrides to apply their own options this would supersede it. The best we could do is make apply labels call the new macro internally and just print the label as it did before, that means callers of apply_label would work as before, but that is the same effect as just leaving apply_label as is, just without the duplication of code.
The risk surface is users who are overriding apply_label. If they are over riding it to do something other than applying a label because it was a useful injection point then they will have a migration issue, but I cannot see a way around that other than notifying them of the new path. I wouldn't call it a breaking change, as its a not a proper usage of the macro.
- Drop `| int` cast so MAX_GRANT_PERCENT / MIN_GRANT_PERCENT render decimals verbatim (SQL Server accepts 0.0–100.0). - Remove PARAMETERIZATION from the allowlist — its SIMPLE/FORCED syntax cannot be rendered through the numeric value path. Users needing it can fall back to query_options_raw. - Reject string/mapping values for query_options_raw to prevent silent character-by-character iteration when a non-list is passed. - Sharpen the apply_label() deprecation comment to direct overriders to get_query_options() as the new extension point. - Add CHANGELOG v1.10.0 entry covering the new configs and the apply_label override migration note. - Add tests covering decimal MAX_GRANT_PERCENT, query_options_raw string rejection, and PARAMETERIZATION now hitting the invalid-key branch.
…query-options. Brings in 21 commits from upstream that were missing from this branch (view materialization improvements, multi-database catalog support, TABLOCK on contract-enforced inserts, reserved-keyword quoting fix, default-schema-concat flag, etc.). Conflict in dbt/include/sqlserver/macros/adapters/catalog.sql resolved by keeping upstream's multi-database structure while replacing the remaining apply_label() call with get_query_options().
for more information, see https://pre-commit.ci
Supports a dict form (allowlisted hints; MAX_GRANT_PERCENT / MIN_GRANT_PERCENT use
=syntax) and a query_options_raw escape hatch. Usable on table, incremental (delete+insert, merge, microbatch), snapshot, and unit_test materializations.Usage on a view raises a compiler error if set.
Apply_label() is preserved as a backward-compat alias emitting only the LABEL hint.
Fixes #613