我可以在数据块中创建相当于 SQL 临时 table 的东西吗?
Can I create the equivalent of a SQL temporary table in databricks?
我有一个数据块笔记本,我目前在其中创建了一个基于多个增量 table 的视图,然后根据该视图更新了一些相同的增量 table。但是,我得到的结果不正确,因为随着增量 tables 的变化,视图中的数据也会发生变化。我实际上需要的是在笔记本开始 运行 时拍摄数据快照,然后我可以在整个笔记本中使用它,类似于 SQL 临时 table。目前我正在通过将数据保存到 table 并将 table 放在笔记本末尾来解决这个问题,但我想知道是否有更好的解决方案?
Pinned view of a continuously updating Delta table across multiple downstream jobs 部分包含以下示例代码:
version = spark.sql("SELECT max(version) FROM (DESCRIBE HISTORY my_table)")\
.collect()
# Will use the latest version of the table for all operations below
data = spark.table("my_table@v%s" % version[0][0]
data.where("event_type = e1").write.jdbc("table1")
data.where("event_type = e2").write.jdbc("table2")
...
data.where("event_type = e10").write.jdbc("table10")
我有一个数据块笔记本,我目前在其中创建了一个基于多个增量 table 的视图,然后根据该视图更新了一些相同的增量 table。但是,我得到的结果不正确,因为随着增量 tables 的变化,视图中的数据也会发生变化。我实际上需要的是在笔记本开始 运行 时拍摄数据快照,然后我可以在整个笔记本中使用它,类似于 SQL 临时 table。目前我正在通过将数据保存到 table 并将 table 放在笔记本末尾来解决这个问题,但我想知道是否有更好的解决方案?
Pinned view of a continuously updating Delta table across multiple downstream jobs 部分包含以下示例代码:
version = spark.sql("SELECT max(version) FROM (DESCRIBE HISTORY my_table)")\
.collect()
# Will use the latest version of the table for all operations below
data = spark.table("my_table@v%s" % version[0][0]
data.where("event_type = e1").write.jdbc("table1")
data.where("event_type = e2").write.jdbc("table2")
...
data.where("event_type = e10").write.jdbc("table10")