如何在使用Spark SQL收集时处理列内容中的非ascii字符?

时间:2018-02-16 04:58:09

标签: apache-spark utf-8 pyspark apache-spark-sql ascii

我有一个要求,我需要在Spark驱动程序上收集一些列,而某些列包含非ascii字符。但是收集它们时会产生错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 187: ordinal not in range(128).

任何想法我怎么可以在获取它时将udf应用于列内容然后将其收集到驱动程序中?

我正在使用PySpark。

1 个答案:

答案 0 :(得分:0)

我有同样的问题。这对我有用:

import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

我在这里https://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html