Skip to content

Commit

Permalink
fix: staging and mart models (#1359)
Browse files Browse the repository at this point in the history
* Add a .sqlfluff to match dbt style guide
* Add .sqlfluffignore for anything outside of dbt right now
* Fixed up the staging and mart models.
NOTE: This is currently broken, the intermediate models have not yet
been fixed to connect the 2 ends
  • Loading branch information
ryscheng authored May 3, 2024
1 parent c9efaba commit 873d6b2
Show file tree
Hide file tree
Showing 133 changed files with 2,391 additions and 2,278 deletions.
38 changes: 38 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[sqlfluff]
dialect = bigquery
templater = dbt
runaway_limit = 10
max_line_length = 80
indent_unit = space

[sqlfluff:indentation]
tab_space_size = 4

[sqlfluff:layout:type:comma]
spacing_before = touch
line_position = trailing

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower

[sqlfluff:rules:aliasing.table]
aliasing = explicit

[sqlfluff:rules:aliasing.column]
aliasing = explicit

[sqlfluff:rules:aliasing.expression]
allow_scalar = False

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.functions]
capitalisation_policy = lower

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower

[sqlfluff:rules:ambiguous.column_references] # Number in group by
group_by_and_order_by_style = consistent
#group_by_and_order_by_style = explicit
14 changes: 14 additions & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# dbt-related
/target/
/dbt_packages/
/warehouse/dbt/macros/

# Non-dbt SQL
/apps/
/ops/
/warehouse/oso_dagster/

# Dependencies
/.venv/
/node_modules/
2 changes: 1 addition & 1 deletion warehouse/dbt/macros/models/goog_blockchain_deployers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#}

{% macro goog_blockchain_deployers(network_name) %}
{% if is_incremental() %}
{% if is_incremental() %}
WITH max_block_timestamp AS (
{# If there's no existing max time then we arbitrarily query at unix time 0 #}
SELECT COALESCE(MAX(block_timestamp), '1970-01-01') as ts
Expand Down
22 changes: 11 additions & 11 deletions warehouse/dbt/macros/oso_artifact_id.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% macro oso_artifact_id(prefix, table_alias="") -%}
{%- set _prefix = prefix -%}
{%- if not prefix.endswith('_') and prefix != "" %}
{%- set _prefix = prefix + '_' -%}
{% endif -%}
{%- if table_alias != "" %}
{%- set _prefix = "%s.%s" % (table_alias, _prefix) -%}
{% endif -%}
{%- set namespace = "%s%s" % (_prefix, 'namespace') -%}
{%- set source_id = "%s%s" % (_prefix, 'source_id') -%}
{%- set type = "%s%s" % (_prefix, 'type') -%}
{{- oso_id(namespace, type, source_id) -}}
{%- set _prefix = prefix -%}
{%- if not prefix.endswith('_') and prefix != "" %}
{%- set _prefix = prefix + '_' -%}
{% endif -%}
{%- if table_alias != "" %}
{%- set _prefix = "%s.%s" % (table_alias, _prefix) -%}
{% endif -%}
{%- set namespace = "%s%s" % (_prefix, 'namespace') -%}
{%- set source_id = "%s%s" % (_prefix, 'source_id') -%}
{%- set type = "%s%s" % (_prefix, 'type') -%}
{{- oso_id(namespace, type, source_id) -}}
{%- endmacro %}
4 changes: 2 additions & 2 deletions warehouse/dbt/macros/oso_id.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{# Generates an ID for OSO. For now this is done by creating a url safe base64 encoding of a SHA256 #}
{% macro oso_id() -%}
{%- set id_bytes = 'SHA256(CONCAT(' + ', '.join(varargs) + '))' -%}
{{- urlsafe_base64(id_bytes) -}}
{%- set id_bytes = 'SHA256(CONCAT(' + ', '.join(varargs) + '))' -%}
{{- urlsafe_base64(id_bytes) -}}
{%- endmacro %}
9 changes: 6 additions & 3 deletions warehouse/dbt/macros/oso_source.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
in the playground. Use this instead of source.
#}
{%- macro oso_source(source_name, table_name) -%}
{%- if target.name in ['playground', 'dev'] -%} {{ ref('%s__%s' % (source_name, table_name)) }}
{%- else -%} {{ source(source_name, table_name) }}
{%- endif -%}
{%- if target.name in ['playground', 'dev'] -%}
{{ ref('%s__%s' % (source_name, table_name)) }}

{%- else -%}
{{ source(source_name, table_name) }}
{%- endif -%}
{%- endmacro -%}
2 changes: 1 addition & 1 deletion warehouse/dbt/macros/urlsafe_base64.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# urlsafe_base64 Macro #}
{% macro urlsafe_base64(bytes_column) -%}
REPLACE(REPLACE(TO_BASE64({{ bytes_column }}), '+', '-'), '/', '_')
REPLACE(REPLACE(TO_BASE64({{ bytes_column }}), '+', '-'), '/', '_')
{%- endmacro %}

This file was deleted.

Loading

0 comments on commit 873d6b2

Please sign in to comment.