如何缓存 Spark 数据帧并在另一个脚本中引用它 [英] How to cache a Spark data frame and reference it in another script
问题描述
是否可以缓存数据框,然后在另一个脚本中引用(查询)它?...我的目标如下:
Is it possible to cache a data frame and then reference (query) it in another script?...My goal is as follows:
- 在脚本 1 中,创建一个数据框 (df)
- 运行脚本 1 并缓存 df
- 在脚本2中,查询df中的数据
推荐答案
使用标准 Spark 二进制文件是不可能的.Spark DataFrame
绑定到用于创建它的特定 SQLContext
并且无法在其外部访问.
It is not possible using standard Spark binaries. Spark DataFrame
is bound to the specific SQLContext
which has been used to create it and is not accessible outside it.
有一些工具,例如 Apache Zeppelin 或 Databricks,它们使用注入不同会话的共享上下文.这是您可以在不同会话和/或来宾语言之间共享临时表的方式.
There are tools, like for example Apache Zeppelin or Databricks, which use shared context injected into different sessions. This is way you can share temporary tables between different sessions and or guest languages.
还有其他平台,包括spark-jobserver
和 Apache Ignite,它们提供了替代方法共享分布式数据结构.您还可以查看 Livy 服务器.
There are other platforms, including spark-jobserver
and Apache Ignite, which provide alternative ways to share distributed data structures. You can also take a look at the Livy server.
另见:在同一 Master 下的 Java 和 R 应用程序之间共享 SparkContext
这篇关于如何缓存 Spark 数据帧并在另一个脚本中引用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!