apache-spark - AnalysisException:CSV 数据源不支持数组
我在工作,我需要立即帮助,请我有一个镶木地板文件,我需要将其转换为 csv。你能帮帮我吗?
错误:
AnalysisException: CSV data source does not support array<struct<company:string,dateRange:string,description:str
问题描述
我在工作,我需要立即帮助,请我有一个镶木地板文件,我需要将其转换为 csv。你能帮帮我吗?
错误:
AnalysisException: CSV data source does not support array<struct<company:string,dateRange:string,description:string,location:string,title:string>> data type.
我从来没有使用过这种格式,所以我什至不能打印模式。对不起
printshema:
root
|-- _id: string (nullable = true)
|-- Locale: string (nullable = true)
|-- workExperience: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- company: string (nullable = true)
| | |-- dateRange: string (nullable = true)
| | |-- description: string (nullable = true)
| | |-- location: string (nullable = true)
| | |-- title: string (nullable = true)
您无法将包含数组/结构类型列的数据框保存到 CSV。您需要在写入之前将列转换为字符串。
df.withColumn('workExperience', col('workExperience').cast('string')).write.csv('path')
解决方案
parquet 模式可以使用explode 展平:
df=spark.read.parquet(...)
flattened_df = df.withColumn("tmp", F.explode("workExperience")) \
.selectExpr("_id", "Locale", "tmp.*")
flattened_df.write.csv(...)
推荐阅读
- typescript - 返回从使用 Typescript 传递的泛型参数推断的排序内部类型
- c++ - std::bind 和/或 std::forward 的语义
- c++ - OpenCV FAST 操作。为什么使用 FAST 而不是 FastFeatureDetector
- cockpit - 在哪里可以找到知识驾驶舱?
- python - Celery Task 的 init() 无法识别传递的参数
- flutter - 如何在 Flutter 中混合 2 个 json 响应到 1 个列表
- django - 如何使用自定义函数注释 Django QuerySet?
- python - Python 正则表达式非贪婪的方式来匹配/选择引号内的字符串,但字符串有时包含括号、逗号、反斜杠和拉停
- c++ - 如何在 C++ 中定义 3D 决策变量(使用 CPLEX Concert 技术)?
- excel - VBA 在用户窗体处于活动状态时仅启用工作表滚动
我在工作,我需要立即帮助,请我有一个镶木地板文件,我需要将其转换为 csv。你能帮帮我吗?
错误:
AnalysisException: CSV data source does not support array<struct<company:string,dateRange:string,description:str
问题描述
我在工作,我需要立即帮助,请我有一个镶木地板文件,我需要将其转换为 csv。你能帮帮我吗?
错误:
AnalysisException: CSV data source does not support array<struct<company:string,dateRange:string,description:string,location:string,title:string>> data type.
我从来没有使用过这种格式,所以我什至不能打印模式。对不起
printshema:
root
|-- _id: string (nullable = true)
|-- Locale: string (nullable = true)
|-- workExperience: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- company: string (nullable = true)
| | |-- dateRange: string (nullable = true)
| | |-- description: string (nullable = true)
| | |-- location: string (nullable = true)
| | |-- title: string (nullable = true)
您无法将包含数组/结构类型列的数据框保存到 CSV。您需要在写入之前将列转换为字符串。
df.withColumn('workExperience', col('workExperience').cast('string')).write.csv('path')
解决方案
parquet 模式可以使用explode 展平:
df=spark.read.parquet(...)
flattened_df = df.withColumn("tmp", F.explode("workExperience")) \
.selectExpr("_id", "Locale", "tmp.*")
flattened_df.write.csv(...)
推荐阅读
- typescript - 返回从使用 Typescript 传递的泛型参数推断的排序内部类型
- c++ - std::bind 和/或 std::forward 的语义
- c++ - OpenCV FAST 操作。为什么使用 FAST 而不是 FastFeatureDetector
- cockpit - 在哪里可以找到知识驾驶舱?
- python - Celery Task 的 init() 无法识别传递的参数
- flutter - 如何在 Flutter 中混合 2 个 json 响应到 1 个列表
- django - 如何使用自定义函数注释 Django QuerySet?
- python - Python 正则表达式非贪婪的方式来匹配/选择引号内的字符串,但字符串有时包含括号、逗号、反斜杠和拉停
- c++ - 如何在 C++ 中定义 3D 决策变量(使用 CPLEX Concert 技术)?
- excel - VBA 在用户窗体处于活动状态时仅启用工作表滚动