-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
atualiza tratamento de fare_rule e feed_info
- Loading branch information
Showing
3 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
{{config( | ||
materialized='table', | ||
materialized='incremental', | ||
partition_by = { 'field' :'feed_start_date', | ||
'data_type' :'date', | ||
'granularity': 'day' }, | ||
alias = 'feed_info' | ||
alias = 'feed_info', | ||
unique_key = 'feed_start_date', | ||
incremental_strategy = 'insert_overwrite' | ||
)}} | ||
|
||
|
||
SELECT | ||
SAFE_CAST(timestamp_captura AS STRING) AS feed_version, | ||
SAFE_CAST(data_versao AS DATE) AS feed_start_date, | ||
DATE_SUB(LEAD(DATE(data_versao)) OVER (ORDER BY data_versao), INTERVAL 1 DAY) AS feed_end_date, | ||
SAFE_CAST(feed_publisher_name AS STRING) feed_publisher_name, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_publisher_url') AS STRING) feed_publisher_url, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_lang') AS STRING) feed_lang, | ||
SAFE_CAST(JSON_VALUE(content, '$.default_lang') AS STRING) default_lang, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_contact_email') AS STRING) feed_contact_email, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_contact_url') AS STRING) feed_contact_url, | ||
'{{ var("version") }}' AS versao_modelo | ||
FROM | ||
{{ source( | ||
'br_rj_riodejaneiro_gtfs_staging', | ||
'feed_info' | ||
) }} | ||
WITH feed_info AS ( | ||
SELECT | ||
SAFE_CAST(timestamp_captura AS STRING) AS feed_version, | ||
SAFE_CAST(data_versao AS DATE) AS feed_start_date, | ||
NULL AS feed_end_date, | ||
SAFE_CAST(feed_publisher_name AS STRING) feed_publisher_name, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_publisher_url') AS STRING) feed_publisher_url, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_lang') AS STRING) feed_lang, | ||
SAFE_CAST(JSON_VALUE(content, '$.default_lang') AS STRING) default_lang, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_contact_email') AS STRING) feed_contact_email, | ||
SAFE_CAST(JSON_VALUE(content, '$.feed_contact_url') AS STRING) feed_contact_url, | ||
CURRENT_DATETIME("America/Sao_Paulo") AS feed_update_datetime, | ||
'{{ var("version") }}' AS versao_modelo | ||
FROM | ||
{{ source( | ||
'br_rj_riodejaneiro_gtfs_staging', | ||
'feed_info' | ||
) }} | ||
{% if is_incremental() %} | ||
WHERE | ||
data_versao = '{{ var("data_versao_gtfs") }}' | ||
UNION ALL | ||
SELECT | ||
* | ||
FROM | ||
{{ this }} | ||
WHERE | ||
feed_start_date != DATE('{{ var("data_versao_gtfs") }}') | ||
{% endif %} | ||
) | ||
SELECT | ||
feed_version, | ||
feed_start_date, | ||
DATE_SUB(LEAD(DATE(feed_version)) OVER (ORDER BY feed_version), INTERVAL 1 DAY) AS feed_end_date, | ||
feed_publisher_name, | ||
feed_publisher_url, | ||
feed_lang, | ||
default_lang, | ||
feed_contact_email, | ||
feed_contact_url, | ||
feed_update_datetime, | ||
versao_modelo | ||
FROM | ||
feed_info |