如何将 Hive 表导出到 CSV 文件,其中我的文件包含警告非法字符的 CJK 单词

发布于 2025-01-13 04:11:00 字数 429 浏览 2 评论 0原文

df = sol.spark.sql("SELECT * FROM mytable")

df.write.csv("hdfs:///user/athena_ioc/mydata.csv")

在这种情况下我使用 pyspark,所以这里我使用 Spark 数据帧,它无法指定编码样式,在将某些内容导出到我的 HDFS 后,它显示许多非法字符,其中我的表包含 CJK 单词,我该如何处理?

查看我的文件设置后,它显示我的原始编码是 cp936,当前使用 Spark 2.3 版本,我知道它有点旧,或者还有其他方式导出数据吗?

不过,我听说可以使用pandas提供的功能传输到pandas dataframe并导出到excel文件,但在我们的hadoop集群中我们实际上并没有安装这类东西,因此向我们的维护寻求帮助会花费更多时间这不是一个好方法。

非常感谢

df = sol.spark.sql("SELECT * FROM mytable")

df.write.csv("hdfs:///user/athena_ioc/mydata.csv")

I am using pyspark in this case, so here i am using spark dataframe where it cannot specify encoding style, after exported something to my HDFS it shows many illegal characters where my table contains CJK words, How do i dealing with that?

after looking at my file settings it shows my original encoding is cp936, currently using spark 2.3 version which i know it is a bit old, or is there any other way to export data?

however, I have heard that trasnfer to pandas dataframe and exported to a excel file by using functions that pandas provided, but in our hadoop cluster we did not actually install that kinds of thing so it would cost more time to asking help from our maintenance therefore this would not be a good approach.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2025-01-20 04:11:00

保存 csv 文件时应指定其字符集。

df.write.csv("hdfs:///user/athena_ioc/mydata.csv", encoding="UTF-8")

You should specify its charset when saving the csv file.

df.write.csv("hdfs:///user/athena_ioc/mydata.csv", encoding="UTF-8")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文