|
26 | 26 | 'MAXRECURSION', |
27 | 27 | 'NO_PERFORMANCE_SPOOL', |
28 | 28 | 'OPTIMIZE FOR UNKNOWN', |
29 | | - 'PARAMETERIZATION', |
30 | 29 | 'QUERYTRACEON', |
31 | 30 | 'RECOMPILE', |
32 | 31 | 'ROBUST PLAN', |
|
46 | 45 | {{ exceptions.raise_compiler_error("Query option '" ~ key ~ "' value must be a number, got: '" ~ value ~ "'") }} |
47 | 46 | {%- endif -%} |
48 | 47 | {%- set separator = ' = ' if key | upper in equals_syntax_options else ' ' -%} |
49 | | - {%- do options_list.append(key | upper ~ separator ~ value | int) -%} |
| 48 | + {#- Render the value verbatim: ints become "1", floats become "12.5". |
| 49 | + MAX_GRANT_PERCENT / MIN_GRANT_PERCENT accept decimals 0.0–100.0; integer-only |
| 50 | + options will surface a clear SQL Server parse error on invalid decimals. -#} |
| 51 | + {%- do options_list.append(key | upper ~ separator ~ value) -%} |
50 | 52 | {%- endif -%} |
51 | 53 | {%- endfor -%} |
52 | 54 |
|
53 | | - {#- query_options_raw bypasses the allowlist; users opt in to writing valid SQL Server syntax themselves. -#} |
| 55 | + {#- query_options_raw bypasses the allowlist; users opt in to writing valid SQL Server syntax themselves. |
| 56 | + Shape-check only: a plain string would be iterated character-by-character into garbage. -#} |
| 57 | + {%- if query_options_raw is string or query_options_raw is mapping -%} |
| 58 | + {{ exceptions.raise_compiler_error("query_options_raw must be a list of strings, got: '" ~ query_options_raw ~ "'") }} |
| 59 | + {%- endif -%} |
54 | 60 | {%- for raw in query_options_raw -%} |
55 | 61 | {%- do options_list.append(raw) -%} |
56 | 62 | {%- endfor -%} |
|
59 | 65 | OPTION ({{ options_list | join(', ') }}); |
60 | 66 | {% endmacro %} |
61 | 67 |
|
62 | | -{#- Backward-compat alias for the pre-1.10 macro. Emits only the LABEL hint |
63 | | - and ignores query_options / query_options_raw. New adapter code should |
64 | | - call get_query_options() directly. |
65 | | - |
66 | | - Note: this preserves non-breaking *consumption* of apply_label (user |
67 | | - macros calling `{{ apply_label() }}` still resolve), but does NOT |
68 | | - preserve non-breaking *override*: adapter macros no longer call |
69 | | - apply_label internally, so a project that overrides apply_label in its |
70 | | - own macros directory will find that override has no effect on adapter |
71 | | - behaviour. To customise the OPTION clause emitted by adapter macros, |
72 | | - override get_query_options instead. -#} |
| 68 | +{#- DEPRECATED: backward-compat alias for the pre-1.10 macro. |
| 69 | + |
| 70 | + Calls to `{{ apply_label() }}` from user macros still resolve and emit |
| 71 | + a LABEL-only OPTION clause — but apply_label() is no longer the |
| 72 | + extension point. Adapter macros now call get_query_options() instead, |
| 73 | + so overriding apply_label() in a project's macros directory will have |
| 74 | + no effect on adapter-emitted SQL. |
| 75 | +
|
| 76 | + To customise the OPTION clause emitted by adapter macros (table, |
| 77 | + incremental, snapshot, unit_test), override get_query_options instead. -#} |
73 | 78 | {% macro apply_label() %} |
74 | 79 | {{ log (config.get('query_tag','dbt-sqlserver'))}} |
75 | 80 | {%- set query_label = config.get('query_tag','dbt-sqlserver') -%} |
|
125 | 130 | {% macro sqlserver__list_relations_without_caching(schema_relation) -%} |
126 | 131 | {% call statement('list_relations_without_caching', fetch_result=True) -%} |
127 | 132 | {{ get_use_database_sql(schema_relation.database) }} |
128 | | - with base as ( |
129 | | - select |
130 | | - DB_NAME() as [database], |
131 | | - t.name as [name], |
132 | | - SCHEMA_NAME(t.schema_id) as [schema], |
133 | | - 'table' as table_type |
134 | | - from sys.tables as t {{ information_schema_hints() }} |
135 | | - union all |
136 | | - select |
137 | | - DB_NAME() as [database], |
138 | | - v.name as [name], |
139 | | - SCHEMA_NAME(v.schema_id) as [schema], |
140 | | - 'view' as table_type |
141 | | - from sys.views as v {{ information_schema_hints() }} |
142 | | - ) |
143 | | - select * from base |
144 | | - where [schema] like '{{ schema_relation.schema }}' |
| 133 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 134 | + select |
| 135 | + DB_NAME() as [database], |
| 136 | + t.name as [name], |
| 137 | + '{{ schema_relation.schema }}' as [schema], |
| 138 | + 'table' as table_type |
| 139 | + from sys.tables as t {{ information_schema_hints() }} |
| 140 | + where t.schema_id = @schema_id |
| 141 | + union all |
| 142 | + select |
| 143 | + DB_NAME() as [database], |
| 144 | + v.name as [name], |
| 145 | + '{{ schema_relation.schema }}' as [schema], |
| 146 | + 'view' as table_type |
| 147 | + from sys.views as v {{ information_schema_hints() }} |
| 148 | + where v.schema_id = @schema_id |
145 | 149 | {{ get_query_options() }} |
146 | 150 | {% endcall %} |
147 | 151 | {{ return(load_result('list_relations_without_caching').table) }} |
|
150 | 154 | {% macro sqlserver__get_relation_without_caching(schema_relation) -%} |
151 | 155 | {% call statement('get_relation_without_caching', fetch_result=True) -%} |
152 | 156 | {{ get_use_database_sql(schema_relation.database) }} |
153 | | - with base as ( |
154 | | - select |
155 | | - DB_NAME() as [database], |
156 | | - t.name as [name], |
157 | | - SCHEMA_NAME(t.schema_id) as [schema], |
158 | | - 'table' as table_type |
159 | | - from sys.tables as t {{ information_schema_hints() }} |
160 | | - union all |
161 | | - select |
162 | | - DB_NAME() as [database], |
163 | | - v.name as [name], |
164 | | - SCHEMA_NAME(v.schema_id) as [schema], |
165 | | - 'view' as table_type |
166 | | - from sys.views as v {{ information_schema_hints() }} |
167 | | - ) |
168 | | - select * from base |
169 | | - where [schema] like '{{ schema_relation.schema }}' |
170 | | - and [name] like '{{ schema_relation.identifier }}' |
| 157 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 158 | + select |
| 159 | + DB_NAME() as [database], |
| 160 | + t.name as [name], |
| 161 | + '{{ schema_relation.schema }}' as [schema], |
| 162 | + 'table' as table_type |
| 163 | + from sys.tables as t {{ information_schema_hints() }} |
| 164 | + where t.schema_id = @schema_id and t.name = '{{ schema_relation.identifier }}' |
| 165 | + union all |
| 166 | + select |
| 167 | + DB_NAME() as [database], |
| 168 | + v.name as [name], |
| 169 | + '{{ schema_relation.schema }}' as [schema], |
| 170 | + 'view' as table_type |
| 171 | + from sys.views as v {{ information_schema_hints() }} |
| 172 | + where v.schema_id = @schema_id and v.name = '{{ schema_relation.identifier }}' |
171 | 173 | {{ get_query_options() }} |
172 | 174 | {% endcall %} |
173 | 175 | {{ return(load_result('get_relation_without_caching').table) }} |
|
178 | 180 | {% endmacro %} |
179 | 181 |
|
180 | 182 | {% macro sqlserver__get_view_definition_sql(relation) -%} |
| 183 | + {%- set object_name = "quotename('" ~ relation.schema ~ "') + '.' + quotename('" ~ relation.identifier ~ "')" -%} |
181 | 184 | {{ get_use_database_sql(relation.database) }} |
182 | | - select object_definition(v.object_id) as definition |
183 | | - from sys.views as v {{ information_schema_hints() }} |
184 | | - inner join sys.schemas as s {{ information_schema_hints() }} |
185 | | - on v.schema_id = s.schema_id |
186 | | - where upper(s.name) = upper('{{ relation.schema }}') |
187 | | - and upper(v.name) = upper('{{ relation.identifier }}') |
| 185 | + select object_definition(object_id({{ object_name }}, 'V')) as definition |
| 186 | + where object_id({{ object_name }}, 'V') is not null |
188 | 187 | {% endmacro %} |
189 | 188 |
|
190 | 189 | {% macro sqlserver__get_relation_last_modified(information_schema, relations) -%} |
|
0 commit comments