apache-spark - PySpark DataFrame - 强制急切的数据帧缓存 - take(1) 与 count()

标签 apache-spark apache-spark-sql

强制缓存/持久化的方法之一是在缓存/持久化之后调用一个操作,例如:

df.cache().count()

正如这里提到的:in spark streaming must i call count() after cache() or persist() to force caching/persistence to really happen?

问题:

如果调用 take(1) 而不是 count() 有什么区别吗?使用 take(1) 时,整个数据帧是否会缓存到内存和/或磁盘中?

我注意到 df.cache().take(1) 更快,但我的目的只是实现急切的缓存。

最佳答案

如果您使用 take(1),那么它将仅评估数据帧的一部分,而不是整个数据帧 - 这就是为什么 count 更常用,尽管任何可以使用评估整个数据帧的其他操作。

Learning Spark第二版书中特别提到了这个案例,即freely available from Databrick's site .

关于apache-spark - PySpark DataFrame - 强制急切的数据帧缓存 - take(1) 与 count(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63404399/

相关文章:

dataframe - 如何创建具有指定模式的空 DataFrame?

hadoop - HDFS保存数据的格式有哪些?

python - "any value"的 PySpark 聚合函数

apache-spark - 列数据到Spark结构化流中的嵌套json对象

apache-spark - pyspark折叠方法输出

java - 使用 Java 将数据存储为 Apache Spark 中的 Hive 表

apache-spark - Spark/Yarn-连接错误RetryingBlockFetcher尝试从随机端口获取 block

scala - 错误 : Must specify a primary resource (JAR or Python file) - Spark scala

hadoop - 如何在 spark 中处理后发布单个 Parquet 文件

python - 如何使用 Spark Data Frame 中前一行的两列计算一行中的列?