【问题标题】:Exporting Spark DataFrame to S3将 Spark DataFrame 导出到 S3
【发布时间】:2021-05-14 04:46:36
【问题描述】:

所以在某些操作之后,我在 Spark DataFrame 中有一些数据,具体来说,org.apache.spark.sql.DataFrame = [_1: string, _2: string ... 1 more field]

现在当我执行df.show() 时,我得到以下输出,这是预期的。

+--------------------+--------------------+--------------------+
|                  _1|                  _2|                  _3|
+--------------------+--------------------+--------------------+
|industry_name_ANZSIC|'industry_name_AN...|.isComplete("indu...|
|industry_name_ANZSIC|'industry_name_AN...|.isContainedIn("i...|
|industry_name_ANZSIC|'industry_name_AN...|.isContainedIn("i...|
|        rme_size_grp|'rme_size_grp' is...|.isComplete("rme_...|
|        rme_size_grp|'rme_size_grp' ha...|.isContainedIn("r...|
|        rme_size_grp|'rme_size_grp' ha...|.isContainedIn("r...|
|                year|  'year' is not null| .isComplete("year")|
|                year|'year' has type I...|.hasDataType("yea...|
|                year|'year' has no neg...|.isNonNegative("y...|
|industry_code_ANZSIC|'industry_code_AN...|.isComplete("indu...|
|industry_code_ANZSIC|'industry_code_AN...|.isContainedIn("i...|
|industry_code_ANZSIC|'industry_code_AN...|.isContainedIn("i...|
|            variable|'variable' is not...|.isComplete("vari...|
|            variable|'variable' has va...|.isContainedIn("v...|
|                unit|  'unit' is not null| .isComplete("unit")|
|                unit|'unit' has value ...|.isContainedIn("u...|
|               value| 'value' is not null|.isComplete("value")|
+--------------------+--------------------+--------------------+

当我尝试将数据帧作为 csv 导出到我的 S3 存储桶时,会出现问题。

我的代码是:df.coalesce(1).write.mode("Append").csv("s3://<my path>")

但是在我的 S3 路径中生成的 csv 充满了乱码或富文本。此外,执行后火花提示不会重新出现(意味着执行没有完成?)这是我的 S3 中生成的 csv 的示例屏幕截图:

我做错了什么,我该如何纠正?

【问题讨论】:

  • 尝试“s3a://
  • 谢谢。这行得通。你能告诉我这里发生了什么吗?为什么使用“s3a”有效?

标签: scala csv apache-spark amazon-s3 amazon-emr


【解决方案1】:

S3:简短描述。

当你更改 URI 方案上的字母时,会产生很大的不同,因为它会导致使用不同的软件来连接 S3。

这是三者的区别:

s3 是 Amazon S3 之上的基于块的覆盖,而 s3n/s3a 不是。这些都是基于对象的。

当关注大小时,s3n 支持高达 5GB 的对象,而 s3a 支持高达 5TB 的对象并具有更高的性能。请注意,s3a 是 s3n 的继承者。

【讨论】:

    猜你喜欢
    • 2018-03-18
    • 1970-01-01
    • 2017-01-09
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多