mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 14:06:44 +00:00
44 lines
1.2 KiB
MySQL
44 lines
1.2 KiB
MySQL
|
|
{% macro streamline_external_table_query(
|
||
|
|
model,
|
||
|
|
partition_function,
|
||
|
|
partition_name,
|
||
|
|
unique_key
|
||
|
|
) %}
|
||
|
|
WITH meta AS (
|
||
|
|
SELECT
|
||
|
|
last_modified AS _inserted_timestamp,
|
||
|
|
file_name,
|
||
|
|
{{ partition_function }} AS {{ partition_name }}
|
||
|
|
FROM
|
||
|
|
TABLE(
|
||
|
|
information_schema.external_table_file_registration_history(
|
||
|
|
start_time => DATEADD('day', -3, CURRENT_TIMESTAMP()),
|
||
|
|
table_name => '{{ source( "bronze_streamline", model) }}')
|
||
|
|
) A
|
||
|
|
)
|
||
|
|
SELECT
|
||
|
|
{{ unique_key }},
|
||
|
|
DATA,
|
||
|
|
_inserted_timestamp,
|
||
|
|
MD5(
|
||
|
|
CAST(
|
||
|
|
COALESCE(CAST({{ unique_key }} AS text), '' :: STRING) AS text
|
||
|
|
)
|
||
|
|
) AS id,
|
||
|
|
s.{{ partition_name }},
|
||
|
|
s.value AS VALUE
|
||
|
|
FROM
|
||
|
|
{{ source(
|
||
|
|
"bronze_streamline",
|
||
|
|
model
|
||
|
|
) }}
|
||
|
|
s
|
||
|
|
JOIN meta b
|
||
|
|
ON b.file_name = metadata$filename
|
||
|
|
AND b.{{ partition_name }} = s.{{ partition_name }}
|
||
|
|
WHERE
|
||
|
|
b.{{ partition_name }} = s.{{ partition_name }}
|
||
|
|
{% endmacro %}
|
||
|
|
|
||
|
|
|