admin管理员组文章数量:1403455
The problem I'm having
I am not able to use dbt.this
on Python incremental models.
The context of why I'm trying to do this
I’m trying to implement incremental Python models in dbt, but I’m running into issues when using the dbt.this
keyword due to a hyphen in my BigQuery project name (marketing-analytics
).
Main code:
if dbt.is_incremental:
# Does not work
max_from_this = f"select max(updated_at_new) from {dbt.this}" # <-- problem
df_raw = dbt.ref("interesting_data").filter(
F.col("updated_at_new") >=session.sql(max_from_this).collect()[0][0]
)
# Works
df_raw = dbt.ref("interesting_data").filter(
F.col("updated_at_new") >= F.date_add(F.current_timestamp(), F.lit(-1))
)
else:
df_core_users = dbt.ref("int_core__users")
Error I've got:
Possibly unquoted identifier marketing-analytics detected. Please consider quoting with backquotes `marketing-analytics`
What I've already tried :
- First error:
max_from_this = f"select max(updated_at_new) from `{dbt.this}`"
and
max_from_this=f"select max(updated_at_new) from `{dbt.this.database}.{dbt.this.schema}.{dbt.this.identifier}`"
Error: Table or view not found `marketing-analytics.test_dataset.posts`
Even though this table exists on BigQuery...
- Namespace error:
max_from_this = f"select max(updated_at_new) from f"`{dbt.this.database}`.`{dbt.this.schema}`.`{dbt.this.identifier}`"
Error: spark_catalog requires a single-part namespace, but got [marketing-analytics, test_dataset]
The problem I'm having
I am not able to use dbt.this
on Python incremental models.
The context of why I'm trying to do this
I’m trying to implement incremental Python models in dbt, but I’m running into issues when using the dbt.this
keyword due to a hyphen in my BigQuery project name (marketing-analytics
).
Main code:
if dbt.is_incremental:
# Does not work
max_from_this = f"select max(updated_at_new) from {dbt.this}" # <-- problem
df_raw = dbt.ref("interesting_data").filter(
F.col("updated_at_new") >=session.sql(max_from_this).collect()[0][0]
)
# Works
df_raw = dbt.ref("interesting_data").filter(
F.col("updated_at_new") >= F.date_add(F.current_timestamp(), F.lit(-1))
)
else:
df_core_users = dbt.ref("int_core__users")
Error I've got:
Possibly unquoted identifier marketing-analytics detected. Please consider quoting with backquotes `marketing-analytics`
What I've already tried :
- First error:
max_from_this = f"select max(updated_at_new) from `{dbt.this}`"
and
max_from_this=f"select max(updated_at_new) from `{dbt.this.database}.{dbt.this.schema}.{dbt.this.identifier}`"
Error: Table or view not found `marketing-analytics.test_dataset.posts`
Even though this table exists on BigQuery...
- Namespace error:
max_from_this = f"select max(updated_at_new) from f"`{dbt.this.database}`.`{dbt.this.schema}`.`{dbt.this.identifier}`"
Error: spark_catalog requires a single-part namespace, but got [marketing-analytics, test_dataset]
1 Answer
Reset to default 0Solved it by playing with bigquery-spark
connector with session. It is really unconvenient.
if dbt.is_incremental:
current_table = (
session
.read
.format("bigquery")
.option("table", f"{dbt.this.schema}.{dbt.this.identifier}")
.load()
)
本文标签:
版权声明:本文标题:How to implement dbt.this in Incremental Python Models when BigQuery project id contains hyphens - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744388043a2603840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论