使用带有特定定界符/分隔符的自动加载器获取 CSV 数据
Ingest CSV data with Auto Loader with Specific Delimiters / separator
我正在尝试加载几个带有复杂分隔符(“~|~”)的 csv 文件
当前代码当前正在加载 csv 文件,但未识别正确的列,因为使用的是分隔符 (",")。
我正在阅读此处的文档 https://docs.databricks.com/spark/latest/structured-streaming/auto-loader-csv.html 但它没有说明任何内容或者至少我看不到它
spark.readStream.format("cloudFiles") \
.option("cloudFiles.format", "csv") \
# The schema location directory keeps track of your data schema over time
.option("cloudFiles.schemaLocation", "<path-to-checkpoint>") \
.load("<path-to-source-data>") \
.writeStream \
.option("mergeSchema", "true") \
.option("checkpointLocation", "<path-to-checkpoint>") \
.start("<path-to-target")
With Auto Loader you can ingest JSON, CSV, PARQUET, AVRO, TEXT, BINARYFILE, and ORC files. See Format options for the options for these file formats.
因此您可以只使用标准 options for CSV files - 您需要 delimiter
(或 sep
)选项:
df = spark.readStream.format("cloudFiles") \
.option("cloudFiles.format", "csv") \
.option("delimiter", "~|~") \
.schema(...) \
.load(...)
我正在尝试加载几个带有复杂分隔符(“~|~”)的 csv 文件
当前代码当前正在加载 csv 文件,但未识别正确的列,因为使用的是分隔符 (",")。
我正在阅读此处的文档 https://docs.databricks.com/spark/latest/structured-streaming/auto-loader-csv.html 但它没有说明任何内容或者至少我看不到它
spark.readStream.format("cloudFiles") \
.option("cloudFiles.format", "csv") \
# The schema location directory keeps track of your data schema over time
.option("cloudFiles.schemaLocation", "<path-to-checkpoint>") \
.load("<path-to-source-data>") \
.writeStream \
.option("mergeSchema", "true") \
.option("checkpointLocation", "<path-to-checkpoint>") \
.start("<path-to-target")
With Auto Loader you can ingest JSON, CSV, PARQUET, AVRO, TEXT, BINARYFILE, and ORC files. See Format options for the options for these file formats.
因此您可以只使用标准 options for CSV files - 您需要 delimiter
(或 sep
)选项:
df = spark.readStream.format("cloudFiles") \
.option("cloudFiles.format", "csv") \
.option("delimiter", "~|~") \
.schema(...) \
.load(...)