【问题标题】:When I exit the spark shell all the dataframe data is gone. Is this normal ?当我退出 spark shell 时,所有数据帧数据都消失了。这是正常的吗?
【发布时间】:2017-06-22 15:50:04
【问题描述】:

我正在学习 Apache Spark。我正在将 CSV 数据加载到数据框中。这可能需要大约 5 分钟(大量数据)。当我退出 spark-shell 并重新登录到 spark-shell 时,数据就消失了。这是正常行为吗?我在文档中找不到任何关于此的内容。如何在会话之间保留数据?

【问题讨论】:

    标签: apache-spark spark-dataframe apache-spark-mllib


    【解决方案1】:

    是的,这是预期的,类似地在 ipython shell 中,如果你创建一个数组,一旦你退出 shell,它就不会被存储。要存储它,您可以这样做:

    import spark.implicits._
    val df = spark.range(10).map(l => l.toInt).toDF() // create a mock data frame
    df.write.parquet("outputfile.parquet") // save it to a file, consider s3 with s3://yourbucket/yourfile.parquet if it is too large
    

    重新启动 shell 后,您可以通过以下方式恢复数据框:

    spark.read.parquet("outputfile.parquet").collect
    

    【讨论】:

    • 感谢您的完整性检查!
    • 为什么建议拨打collect?如果您想要返回 DataFrame,只需使用 spark.read.parquet("outputfile.parquet")
    • 我添加了它,以便在复制粘贴时这个片段说明它适用于这个小例子。我希望有人知道你不应该收集大数据框:)
    猜你喜欢
    • 2014-03-05
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2012-01-29
    • 2021-01-08
    • 1970-01-01
    相关资源
    最近更新 更多