python - com.univocity.parsers.common.TextParsingException:解析输入的长度(1000001)超过最大字符数
问题描述
我正在尝试运行 pyspark 脚本,但出现上述错误。我使用了 option("maxCharsPerCol","1100000") 但无法解决问题。
你能帮我解决这个问题吗?Pyspark 版本 - 2.0.0
我在读取和写入文件时使用以下代码:
阅读:
df_read_file = sqlContext.read.format('com.databricks.spark.csv').option("delimiter", '\001').option("maxCharsPerCol","1000001L").options(header='true',inferSchema='false').load(row['Source File Name Lnd'])
写作:
df.repartition(1).write.format('com.databricks.spark.csv').mode('overwrite').save(output_path, sep='\001',header='True',nullValue=None)
错误:
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 9 in stage 6.0 failed 1 times, most recent failure: Lost task 9.0 in stage 6.0 (TID 15, localhost): com.univocity.parsers.common.TextParsingException: Length of parsed input (1000001) exceeds the maximum number of characters defined in your parser settings (1000000).
Identified line separator characters in the parsed content. This may be the cause of the error. The line separator in your parser settings is set to '\n'. Parsed content:
解决方案
我使用以下选项解决了这个问题:
在我正在使用的某些文件中quote=''
df_read_file = sqlContext.read.format('com.databricks.spark.csv').option("delimiter", '\001').options(header='true', quote='',inferSchema='false').load(row['Source File Name Lnd'])
在我正在使用的一些文件中escape=''
df_read_file = sqlContext.read.format('com.databricks.spark.csv').option("delimiter", '\001').options(header='true', escape='',inferSchema='false').load(row['Source File Name Lnd'])
使用此选项运行我能够解决我的问题。
推荐阅读
- graphql - 如何在java中发送和下载文件作为对GraphQL查询的响应
- c# - 我如何在里面用 BindingList 绑定 c# 类?
- cdi - @Produces 不返回 cdi 代理,而是真实实例
- python - import MySQLdb报错ImportError: cannot import name '_mysql' from 'MySQLdb' (D:\python\lib\site-packages\MySQLdb\__init__.py)
- java - 如何修改骆驼交易所并发送
- javascript - InversifyJS:从多注入定义中注入特定的混凝土
- php - 雄辩的更新或更新时创建隐藏列
- python-3.x - 如何对 DataFrame 的每一行中的“种类”检查值进行矢量化并更新计数?
- android - Android - 通过图像组件循环
- python - 在 Python 的面向对象编程中 self 如何工作?