当我将pyarrow设置为true时,我们使用spark会话,但是当我运行toPandas()时,它将引发错误:
"toPandas attempted Arrow optimization because 'spark.sql.execution.arrow.enabled' is set to true. Please set it to false to disable this"
我能知道为什么会发生吗?
答案 0 :(得分:1)
我在使用 Pyarrow 时遇到了同样的问题。
我的环境:
当我尝试像这样启用 Pyarrow 优化时:
spark.conf.set('spark.sql.execution.arrow.enabled', 'true)
我收到以下警告:
createDataFrame attempted Arrow optimization because 'spark.sql.execution.arrow.enabled' is set to true; however failed by the reason below: TypeError: 'JavaPackage' object is not callable
我通过以下方式解决了这个问题:
import os
from pyspark import SparkConf
spark_config = SparkConf().getAll()
for conf in spark_config:
print(conf)
这将打印火花配置的键值对。
('spark.yarn.jars', 'path\to\jar\files')
jar_names = os.listdir('path\to\jar\files')
for jar_name in jar_names:
if 'arrow' in jar_name:
print(jar_name)
我发现了以下罐子:
arrow-format-0.10.0.jar
arrow-memory-0.10.0.jar
arrow-vector-0.10.0.jar
spark.conf.set('spark.driver.extraClassPath', 'path\to\jar\files\arrow-format-0.10.0.jar:path\to\jar\files\arrow-memory-0.10.0.jar:path\to\jar\files\arrow-vector-0.10.0.jar')
答案 1 :(得分:0)
默认情况下,PyArrow是禁用的,但在您看来已启用的情况下,您必须从当前的spark应用程序会话中或永久从Spark配置文件中手动禁用此配置。
如果要对所有Spark会话禁用此功能,请在SPARK_HOME / conf / spark-defaults.conf中将以下行添加到Spark配置中。
spark.sql.execution.arrow.enabled=false
但是,如果您在spark应用程序中使用熊猫,我建议使用PyArrow,它将加快spark和pandas之间的数据转换。
有关PyArrow的更多信息,请访问我的blog。