首页 > 解决方案 > 有没有办法确定文本文件中多行字段的最佳引号字符?

问题描述

我有一个带有多行的 foobar.txt 文件,如下所示:

|a_column|;|b_xml_column|
|first_value|;|my second value
still line 1
still line 1
still line 1
still line 1
still line 1
still line 1
still line 1|
|my third value|;|the end|

我要阅读的火花代码:

spark.read\
    .option("header", "true")\
    .option("multiLine", "true")\
    .option("delimiter", ";")\
    .option("quote","|")\
    .csv("foobar.txt").show(2, False)

输出:

在此处输入图像描述

但是在现实世界的场景中b_xml_column, 甚至中可能存在任何字符|,这将导致多行读取失败,那么,确定quote这些字段的分隔符的最佳方法是什么?阅读时永远不会失败的那个。

标签: pythoncsvapache-sparkpysparktext-files

解决方案


推荐阅读