使用databricks解析csv数据

问题描述 投票:0回答:1

有一个csv文件,内容如下(分割符为\u0001) enter image description here 尝试以表格形式阅读:

SELECT * FROM read_files(
  '{csv_file_path}',
  format => 'csv',
  header => false,
  sep=>"\u0001",
  quote=>'"',
  escape=>'\\', 
  charToEscapeQuoteEscaping=>'\0',
   nullValue=>'\\N',
  schema => 'id int, name string, ts string')

得到以下结果: enter image description here

记录id=3解析失败。 这是期望:

1 "abc    null
2 \abc    null
3 ab"""c\ null
4 abc"    null
5 \"abc   null
6 ab\\c   null
7 \\"abc  null
8 abc\\"  null

有人可以帮忙解决如何解析 csv 文件吗?多谢。我尝试了很多 csv 选项,但没有成功。

azure azure-data-factory databricks azure-databricks
1个回答
0
投票

问题是记录 #3 没有结束引号。它是用反斜杠转义的。您可以预处理输入文件以查找格式不正确的数据并在进一步处理之前修复它。

对于记录 #3,修复方法是在最终引用之前添加反斜杠。

“ab\”\”\”c\\”

© www.soinside.com 2019 - 2024. All rights reserved.