-
Notifications
You must be signed in to change notification settings - Fork 0
feat(elt-pipelines): dbt project with electricity_sharepoint transform #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
466a0af
feat(elt-pipelines): electricity_sharepoint transform
WHTaylor 27c0a12
docs(elt-pipelines): Interim updates to transform README
WHTaylor 5745e06
Fix dbt test
WHTaylor 2595d86
Remove unused project config
WHTaylor cf39354
Remove requirements from dbt project
WHTaylor ab47bd5
Correct precision of parse_utc_timestamp
WHTaylor 973f5b5
Apply timezone during parsing
WHTaylor b2182c8
Hardcode https for dbt remote configuration
WHTaylor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| logs/ | ||
| target/ | ||
| dbt_packages/ | ||
| spark-warehouse/ | ||
| metastore_db/ | ||
|
|
||
| derby.log | ||
| .user.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| [sqlfluff] | ||
| dialect = trino | ||
| 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 = implicit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| reports | ||
| target | ||
| dbt_packages | ||
| macros |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Facility Operations catalog models | ||
|
|
||
| This is a [dbt](https://docs.getdbt.com/) project which defines transforms for turning the | ||
| raw data in the `facility_ops_landing` warehouse into cleaned models in `facility_ops`. | ||
|
|
||
| **Under construction. Currently only the electricity_sharepoint transforms work.** | ||
|
|
||
| ## Running with elt | ||
|
|
||
| The `elt run` command defined by [`elt-common`](../../../elt-common) can be used to run | ||
| transforms from this project. | ||
|
|
||
| Ingest jobs ingest data into a namespace defined by the | ||
| [ingest directory structure](../../README.md#directory-structure). That namespace can be used | ||
| to run the transform(s) for the pipeline with `elt run facility_ops <namespace> --step transform`. | ||
|
|
||
| ## Running with dbt | ||
|
|
||
| It's also possible to run the transforms (or interact with them in other ways) using `dbt` directly. | ||
|
|
||
| - Use a python environment with [elt-pipelines](../../README.md#setting-up-a-python-virtual-environment) | ||
| or [elt-common](../../../elt-common/README.md#setting-up-a-python-virtual-environment) installed | ||
| - These provide the required `dbt` dependencies, and the `dbt` cli tool | ||
| - Make the dbt project directory (`elt-pipelines/facility_ops/transform`) the working directory | ||
| - Run `dbt deps` to install the project dependencies | ||
| - For running against a local catalog, ensure the docker | ||
| services [are running](../../../infra/local/README.md#local-set-up) | ||
| - Run `dbt` commands whilst in the dbt project directory | ||
| - To run against a remote catalog, ensure the [required environment variables](./profiles.yml) are set up to point to | ||
| the Trino instance, then use the `--profile remote` option when running `dbt` commands |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: facility_ops | ||
| version: "1.0.0" | ||
|
|
||
| # default project points at stack in local/infra | ||
| profile: "local" | ||
|
|
||
| flags: | ||
| require_certificate_validation: True | ||
|
|
||
| model-paths: [ "models" ] | ||
| analysis-paths: [ "analyses" ] | ||
| test-paths: [ "tests" ] | ||
| seed-paths: [ "seeds" ] | ||
| macro-paths: [ "macros" ] | ||
| snapshot-paths: [ "snapshots" ] | ||
|
|
||
| clean-targets: | ||
| # directories to be removed by `dbt clean` | ||
| - "target" | ||
| - "dbt_packages" | ||
|
|
||
| dispatch: | ||
| # Use macros from trino_utils in preference. https://hub.getdbt.com/starburstdata/trino_utils/latest/ | ||
| - macro_namespace: dbt_utils | ||
| search_order: [ "trino_utils", "dbt_utils" ] | ||
| - macro_namespace: dbt_date | ||
| search_order: [ "trino_utils", "dbt_date" ] | ||
| - macro_namespace: metrics | ||
| search_order: [ "trino_utils", "metrics" ] | ||
|
|
||
| models: | ||
| +file_format: parquet | ||
| +materialized: view | ||
| facility_ops: | ||
| # The full schema name of the final tables is "{target_schema}_"{custom_schema}" | ||
| # - 'target_schema' is defined in profiles.yml | ||
| # - 'custom_schema' is defined for each collection of models below | ||
| # See https://docs.getdbt.com/docs/build/custom-schemas | ||
| staging: | ||
| +schema: staging | ||
| marts: | ||
| +materialized: table | ||
| accelerator: | ||
| +schema: accelerator |
4 changes: 4 additions & 0 deletions
4
elt-pipelines/facility_ops/transform/macros/create_equipment_category_key.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- Creates a key for the equipment -> category mapping table | ||
| {%- macro create_equipment_category_key(text_col) -%} | ||
| lower( {{ normalize_whitespace(text_col) }} ) | ||
| {%- endmacro -%} |
8 changes: 8 additions & 0 deletions
8
elt-pipelines/facility_ops/transform/macros/normalize_whitespace.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- Removes leading and trailing whitespace and replaces any multiple-spaces with a single space | ||
| {%- macro normalize_whitespace(text_col) -%} | ||
| {{ return(adapter.dispatch('normalize_whitespace')(text_col)) }} | ||
| {% endmacro %} | ||
|
|
||
| {%- macro default__normalize_whitespace(text_col) -%} | ||
| regexp_replace(trim({{ text_col }}), '\s+', ' ') | ||
| {%- endmacro -%} |
16 changes: 16 additions & 0 deletions
16
elt-pipelines/facility_ops/transform/macros/parse_utc_timestamp.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| -- Parse separate date and time strings into a single UTC timestamp | ||
| {%- macro parse_utc_timestamp(date_col, date_format, time_col, time_format='HH:mm:ss ZZZ', src_timezone='UTC') -%} | ||
| {{ return(adapter.dispatch('parse_utc_timestamp')(date_col, date_format, time_col, time_format, src_timezone)) }} | ||
| {% endmacro %} | ||
|
|
||
|
|
||
| {%- macro trino__parse_utc_timestamp(date_col, date_format, time_col, time_format, src_timezone) -%} | ||
| with_timezone( | ||
| cast( | ||
| parse_datetime({{ adapter.quote(date_col) }} || ' ' || {{ adapter.quote(time_col) }} || ' {{ src_timezone }}', | ||
| '{{ date_format ~ ' ' ~ time_format }}') | ||
| as timestamp(3) | ||
| ), | ||
| '{{ src_timezone }}' | ||
| ) at time zone 'UTC' | ||
| {%- endmacro -%} | ||
23 changes: 23 additions & 0 deletions
23
elt-pipelines/facility_ops/transform/models/marts/accelerator/power_consumption.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| {{ | ||
| config( | ||
| properties={ | ||
| "partitioning": "ARRAY['year(power_measured_at)']", | ||
| }, | ||
| on_table_exists = 'drop' | ||
| ) | ||
| }} | ||
|
|
||
| with | ||
|
|
||
| staged as ( | ||
|
|
||
| select | ||
|
|
||
| power_measured_at, | ||
| total_isis_power_mw | ||
|
|
||
| from {{ ref('stg_electricity_sharepoint_rdm_data') }} | ||
|
|
||
| ) | ||
|
|
||
| select * from staged |
11 changes: 11 additions & 0 deletions
11
elt-pipelines/facility_ops/transform/models/marts/accelerator/power_consumption.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| models: | ||
| - name: power_consumption | ||
| description: > | ||
| The total power consumption for ISIS over time. | ||
| columns: | ||
| - name: power_measured_at | ||
| data_tests: | ||
| - not_null | ||
| - name: total_isis_power_mw | ||
| data_tests: | ||
| - not_null |
7 changes: 7 additions & 0 deletions
7
elt-pipelines/facility_ops/transform/models/staging/estates/_estates__sources.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| version: 2 | ||
|
|
||
| sources: | ||
| - name: estates_electricity_sharepoint | ||
| database: facility_ops_landing | ||
| tables: | ||
| - name: rdm_data |
18 changes: 18 additions & 0 deletions
18
...nes/facility_ops/transform/models/staging/estates/stg_electricity_sharepoint_rdm_data.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| with source as ( | ||
|
|
||
| select * from {{ source('estates_electricity_sharepoint', 'rdm_data') }} | ||
|
|
||
| ), | ||
|
|
||
| renamed as ( | ||
|
|
||
| select | ||
|
|
||
| date_time as power_measured_at, | ||
| isis_elec_total_power_mw as total_isis_power_mw | ||
|
|
||
| from source | ||
|
|
||
| ) | ||
|
|
||
| select * from renamed |
11 changes: 11 additions & 0 deletions
11
...nes/facility_ops/transform/models/staging/estates/stg_electricity_sharepoint_rdm_data.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| models: | ||
| - name: stg_electricity_sharepoint_rdm_data | ||
| description: > | ||
| ISIS electricity consumption. | ||
| columns: | ||
| - name: power_measured_at | ||
| data_tests: | ||
| - not_null | ||
| - name: total_isis_power_mw | ||
| data_tests: | ||
| - not_null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| packages: | ||
| - name: codegen | ||
| package: dbt-labs/codegen | ||
| version: 0.14.0 | ||
| - name: dbt_utils | ||
| package: dbt-labs/dbt_utils | ||
| version: 1.3.3 | ||
| - name: trino_utils | ||
| package: starburstdata/trino_utils | ||
| version: 0.6.0 | ||
| sha1_hash: dc8ade786ecde1c757d4fd39ba36eb7ddc99a6af |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| packages: | ||
| - package: dbt-labs/codegen | ||
| version: 0.14.0 | ||
| - package: dbt-labs/dbt_utils | ||
| version: 1.3.3 | ||
| - package: starburstdata/trino_utils | ||
| version: 0.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| local: | ||
| target: trino | ||
| outputs: | ||
| trino: | ||
| type: trino | ||
| method: ldap | ||
| user: machine-infra | ||
| password: s3cr3t | ||
| host: localhost | ||
| port: 58443 | ||
| http_scheme: https | ||
| database: facility_ops | ||
| schema: analytics | ||
| threads: 8 | ||
| cert: false | ||
| suppress_cert_warning: true | ||
|
|
||
| remote: | ||
| target: trino | ||
| outputs: | ||
| trino: | ||
| type: trino | ||
| method: ldap | ||
| http_scheme: https | ||
| user: "{{ env_var('DBT_TRINO_USER') }}" | ||
| password: "{{ env_var('DBT_TRINO_PASSWORD') }}" | ||
| host: "{{ env_var('DBT_TRINO_HOST') }}" | ||
| port: "{{ env_var('DBT_TRINO_PORT') | int }}" | ||
| database: "{{ env_var('DBT_TRINO_CATALOG') }}" | ||
| schema: "{{ env_var('DBT_TRINO_CATALOG_SCHEMA_PREFIX') }}analytics" | ||
| threads: "{{ env_var('DBT_TRINO_THREADS', '8') | int }}" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions
21
elt-pipelines/facility_ops/transform/tests/fixtures/base_opralogweb__additional_columns.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| select | ||
| cast(1 as integer) as additional_column_id, | ||
| cast('Equipment' as varchar) as column_title | ||
|
|
||
| union all | ||
|
|
||
| select | ||
| cast(2 as integer) as additional_column_id, | ||
| cast('Group' as varchar) as column_title | ||
|
|
||
| union all | ||
|
|
||
| select | ||
| cast(3 as integer) as additional_column_id, | ||
| cast('Lost Time' as varchar) as column_title | ||
|
|
||
| union all | ||
|
|
||
| select | ||
| cast(4 as integer) as additional_column_id, | ||
| cast('Group Leader comments' as varchar) as column_title |
24 changes: 24 additions & 0 deletions
24
elt-pipelines/facility_ops/transform/tests/fixtures/base_opralogweb__chapter_entry.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| select | ||
|
|
||
| cast(100 as integer) as entry_id, | ||
| cast(24 as integer) as principal_logbook, | ||
| cast(1 as integer) as logbook_chapter_no, | ||
| cast(24 as integer) as logbook_id | ||
|
|
||
| union all | ||
|
|
||
| select | ||
|
|
||
| cast(101 as integer) as entry_id, | ||
| cast(24 as integer) as principal_logbook, | ||
| cast(2 as integer) as logbook_chapter_no, | ||
| cast(24 as integer) as logbook_id | ||
|
|
||
| union all | ||
|
|
||
| select | ||
|
|
||
| cast(102 as integer) as entry_id, | ||
| cast(24 as integer) as principal_logbook, | ||
| cast(2 as integer) as logbook_chapter_no, | ||
| cast(24 as integer) as logbook_id |
27 changes: 27 additions & 0 deletions
27
elt-pipelines/facility_ops/transform/tests/fixtures/base_opralogweb__entries.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| select | ||
|
|
||
| cast(100 as integer) as entry_id, | ||
| with_timezone(timestamp '2017-04-25 23:59:59', 'UTC') as fault_occurred_at, | ||
| date '2017-04-24' as fault_date, | ||
| cast('Comment 100' as varchar) as fault_description, | ||
| false as logically_deleted | ||
|
|
||
| union all | ||
|
|
||
| select | ||
|
|
||
| cast(101 as integer) as entry_id, | ||
| with_timezone(timestamp '2024-01-01 00:00:01', 'UTC') as fault_occurred_at, | ||
| date '2024-01-01' as fault_date, | ||
| cast('Comment 101' as varchar) as fault_description, | ||
| false as logically_deleted | ||
|
|
||
| union all | ||
|
|
||
| select | ||
|
|
||
| cast(102 as integer) as entry_id, | ||
| with_timezone(timestamp '2024-01-01 00:01:03', 'UTC') as fault_occurred_at, | ||
| date '2024-01-01' as fault_date, | ||
| cast('Deleted 102' as varchar) as fault_description, | ||
| true as logically_deleted |
9 changes: 9 additions & 0 deletions
9
elt-pipelines/facility_ops/transform/tests/fixtures/base_opralogweb__logbook_chapter.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| select | ||
|
|
||
| cast(1 as integer) as logbook_chapter_no | ||
|
|
||
| union all | ||
|
|
||
| select | ||
|
|
||
| cast(2 as integer) as logbook_chapter_no |
4 changes: 4 additions & 0 deletions
4
elt-pipelines/facility_ops/transform/tests/fixtures/base_opralogweb__logbooks.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| select | ||
|
|
||
| cast(24 as integer) as logbook_id, | ||
| cast('MCR Running Log' as varchar) as logbook_name |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.