我遇到的问题
我有一个BigQuery分区表,我需要在增量模式下从中创建一个表。我找不到如何充分利用新鲜空气
我为什么要这么做的背景
我的BigQuery表在字段_PARTITIONTIME上按DAY进行分区,它需要分区过滤器。
我需要创建一个以该表为源的增量模型,并为每个键创建一个记录来显示最新的记录。
我已经试过了
我在没有完全刷新的情况下进行了尝试,它正在按预期工作。但我想在每个星期天运行完全刷新,因为我收到了错误
Cannot query over table 'my_dataset.my_table' without a filter over column(s) '_PARTITION_LOAD_TIME', '_PARTITIONDATE', '_PARTITIONTIME' that can be used for partition elimination
一些示例代码或错误消息
{{
config(
materialized='incremental',
unique_key='Id'
)
}}
select *
from `my_dataset.my_table`
{% if is_incremental() %}
where _PARTITIONTIME > timestamp_sub(current_timestamp, INTERVAL 1 DAY)
{% endif %}
qualify row_number() over(partition by Id order by SystemModstamp desc) = 1
如果我跑步
dbt run
它工作时没有错误,但当我运行
dbt run --full-refresh
我得到一个错误,说我需要包括分区列。
我尝试了下面的代码来选择小于current_timestamp的所有分区,当模型不在增量模式下运行时,current_timestamp应该选择所有分区。我认为这是有效的。
但是,还有其他解决方案吗?
{{
config(
materialized='incremental',
unique_key='Id'
)
}}
select *
from `my_dataset.my_table`
{% if is_incremental() %}
where _PARTITIONTIME > timestamp_sub(current_timestamp, INTERVAL 1 DAY)
{% else %}
where _PARTITIONTIME < current_timestamp
{% endif %}
qualify row_number() over(partition by Id order by SystemModstamp desc) = 1