簡體   English   中英

如何獲取流增量表的快照作為 Databricks 中的 static 表?

[英]How to get a snapshot of a streaming delta table as a static table in Databricks?

假設我在 Databricks 中有一個流式增量表。 有什么方法可以將流式表的快照作為 static 表?

原因是我需要通過以下方式將此流表與 static 表連接起來:

output = output.join(country_information, ["Country"], "left")

“Output”是一個 static 表,“country_information”是流表。

但是,我收到錯誤:

Append mode error: LeftOuter join with a streaming DataFrame/Dataset on the right and a static DataFrame/Dataset on the left is not supported;

另外,我無法將上面的代碼更改為:

country_information = country_information.join(output, ["Country"], "left")

因為邏輯不通。

如果您有任何想法,請告訴我。 我為我的任務使用 Python,而不是 SQL。

是的,你可以試試這個方法

# Create the snapshot with timestamp
snapshot_time = "2022-10-01 00:00:00"
spark.sql(f"CREATE TABLE snapshot_table_at_time AS SELECT * FROM streaming_table VERSION AS OF '{snapshot_time}'")

然后,您可以將其保存為數據框

snapshot_df = spark.read.format("delta").option("timestampAsOf", snapshot_time).load("streaming_table").toDF()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM