Skip to content

Commit

Permalink
Added delimited identifier conditional for sql server
Browse files Browse the repository at this point in the history
  • Loading branch information
bvkabn committed Sep 20, 2024
1 parent 114b87c commit 14a9239
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 205 deletions.
8 changes: 6 additions & 2 deletions models/dim_dbt__models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ with
command_invocation_id,
node_id,
run_started_at,
"database",
"schema",
name,
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
depends_on_nodes,
package_name,
path,
Expand Down
8 changes: 6 additions & 2 deletions models/dim_dbt__seeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ with
command_invocation_id,
node_id,
run_started_at,
"database",
"schema",
name,
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
package_name,
path,
checksum,
Expand Down
8 changes: 6 additions & 2 deletions models/dim_dbt__snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ with
command_invocation_id,
node_id,
run_started_at,
"database",
"schema",
name,
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
depends_on_nodes,
package_name,
path,
Expand Down
8 changes: 6 additions & 2 deletions models/dim_dbt__sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ with
command_invocation_id,
node_id,
run_started_at,
"database",
"schema",
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
source_name,
loader,
name,
Expand Down
4 changes: 3 additions & 1 deletion models/fct_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ with
rows_affected
{% if target.type == "bigquery" %}, bytes_processed {% endif %},
materialization,
"schema", -- noqa
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
name,
alias,
message
Expand Down
4 changes: 3 additions & 1 deletion models/fct_dbt__seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ with
total_node_runtime,
rows_affected,
materialization,
"schema",
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
name,
alias,
message
Expand Down
4 changes: 3 additions & 1 deletion models/fct_dbt__snapshot_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ with
total_node_runtime,
rows_affected,
materialization,
"schema",
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
name,
alias,
message
Expand Down
40 changes: 18 additions & 22 deletions models/fct_dbt__test_executions.sql
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
with
base as (

select *
from {{ ref('stg_dbt__test_executions') }}

)

, test_executions as (
base as (select * from {{ ref("stg_dbt__test_executions") }}),
test_executions as (

select
test_execution_id
, command_invocation_id
, node_id
, run_started_at
, was_full_refresh
, thread_id
, status
, compile_started_at
, query_completed_at
, total_node_runtime
, rows_affected
, failures
, message
test_execution_id,
command_invocation_id,
node_id,
run_started_at,
was_full_refresh,
thread_id,
status,
compile_started_at,
query_completed_at,
total_node_runtime,
rows_affected,
failures,
message
from base

)

select * from test_executions
select *
from test_executions

2 changes: 1 addition & 1 deletion models/sources/model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ select
cast(null as {{ type_timestamp() }}) as compile_started_at,
cast(null as {{ type_timestamp() }}) as query_completed_at,
cast(null as {{ type_float() }}) as total_node_runtime,
cast(null as {{ type_int() }}) as rows_affected
cast(null as {{ type_int() }}) as rows_affected,
{% if target.type == "bigquery" %}
, cast(null as {{ type_int() }}) as bytes_processed
{% endif %},
Expand Down
4 changes: 2 additions & 2 deletions models/sources/snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ with dummy_cte as (select 1 as foo)
select
cast(null as {{ type_string() }}) as command_invocation_id,
cast(null as {{ type_string() }}) as node_id,
cast(null as {{ type_timestamp() }}) as run_started_at
cast(null as {{ type_timestamp() }}) as run_started_at,
cast(null as {{ type_string() }}) as {% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
cast(null as {{ type_string() }}) as {% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},,
{% endif %},
cast(null as {{ type_string() }}) as name,
cast(null as {{ type_array() }}) as depends_on_nodes,
cast(null as {{ type_string() }}) as package_name,
Expand Down
55 changes: 26 additions & 29 deletions models/staging/stg_dbt__model_executions.sql
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
with
base as (

select *
from {{ ref('model_executions') }}

)

, enhanced as (
base as (select * from {{ ref("model_executions") }}),
enhanced as (

select
{{ dbt_artifacts.generate_surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id
, command_invocation_id
, node_id
, run_started_at
, was_full_refresh
, {{ split_part('thread_id', "'-'", 2) }} as thread_id
, status
, compile_started_at
, query_completed_at
, total_node_runtime
, rows_affected
{% if target.type == 'bigquery' %}
, bytes_processed
{% endif %}
, materialization
, "schema" -- noqa
, name
, alias
, message
, adapter_response
{{ dbt_artifacts.generate_surrogate_key(["command_invocation_id", "node_id"]) }}
as model_execution_id,
command_invocation_id,
node_id,
run_started_at,
was_full_refresh,
{{ split_part("thread_id", "'-'", 2) }} as thread_id,
status,
compile_started_at,
query_completed_at,
total_node_runtime,
rows_affected
{% if target.type == "bigquery" %}, bytes_processed {% endif %},
materialization,
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %}, -- noqa
name,
alias,
message,
adapter_response
from base

)

select * from enhanced
select *
from enhanced

49 changes: 25 additions & 24 deletions models/staging/stg_dbt__models.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
with
base as (

select *
from {{ ref('models') }}

)

, enhanced as (
base as (select * from {{ ref("models") }}),
enhanced as (

select
{{ dbt_artifacts.generate_surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id
, command_invocation_id
, node_id
, run_started_at
, "database"
, "schema"
, name
, depends_on_nodes
, package_name
, path
, checksum
, materialization
, tags
, meta
, alias
{{ dbt_artifacts.generate_surrogate_key(["command_invocation_id", "node_id"]) }}
as model_execution_id,
command_invocation_id,
node_id,
run_started_at,
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %}, -- noqa
name,
depends_on_nodes,
package_name,
path,
checksum,
materialization,
tags,
meta,
alias
from base

)

select * from enhanced
select *
from enhanced

51 changes: 25 additions & 26 deletions models/staging/stg_dbt__seed_executions.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
with
base as (

select *
from {{ ref('seed_executions') }}

)

, enhanced as (
base as (select * from {{ ref("seed_executions") }}),
enhanced as (

select
{{ dbt_artifacts.generate_surrogate_key(['command_invocation_id', 'node_id']) }} as seed_execution_id
, command_invocation_id
, node_id
, run_started_at
, was_full_refresh
, {{ split_part('thread_id', "'-'", 2) }} as thread_id
, status
, compile_started_at
, query_completed_at
, total_node_runtime
, rows_affected
, materialization
, "schema" -- noqa
, name
, alias
, message
, adapter_response
{{ dbt_artifacts.generate_surrogate_key(["command_invocation_id", "node_id"]) }}
as seed_execution_id,
command_invocation_id,
node_id,
run_started_at,
was_full_refresh,
{{ split_part("thread_id", "'-'", 2) }} as thread_id,
status,
compile_started_at,
query_completed_at,
total_node_runtime,
rows_affected,
materialization,
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %}, -- noqa
name,
alias,
message,
adapter_response
from base

)

select * from enhanced
select *
from enhanced

43 changes: 22 additions & 21 deletions models/staging/stg_dbt__seeds.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
with
base as (

select *
from {{ ref('seeds') }}

)

, enhanced as (
base as (select * from {{ ref("seeds") }}),
enhanced as (

select
{{ dbt_artifacts.generate_surrogate_key(['command_invocation_id', 'node_id']) }} as seed_execution_id
, command_invocation_id
, node_id
, run_started_at
, "database"
, "schema"
, name
, package_name
, path
, checksum
, meta
, alias
{{ dbt_artifacts.generate_surrogate_key(["command_invocation_id", "node_id"]) }}
as seed_execution_id,
command_invocation_id,
node_id,
run_started_at,
{% if target.type == "sqlserver" %} "database"
{% else %} database
{% endif %},
{% if target.type == "sqlserver" %} "schema"
{% else %} schema
{% endif %},
name,
package_name,
path,
checksum,
meta,
alias
from base

)

select * from enhanced
select *
from enhanced

Loading

0 comments on commit 14a9239

Please sign in to comment.