如何在Jupyter PySpark会话中更改SparkContext属性spark.sql.pivotMaxValues

2024-09-24 22:28:17 发布

您现在位置:Python中文网/ 问答频道 /正文

问:如何更改SparkContext属性spark.sql.pivotMaxValues在jupyter Pypark会议上

我做了以下代码更改以增加spark.sql.pivotMaxValues. 遗憾的是,在重新启动jupyter并再次运行代码之后,它对所产生的错误没有任何影响。在

from pyspark import SparkConf, SparkContext
from pyspark.mllib.linalg import Vectors
from pyspark.mllib.linalg.distributed import RowMatrix
import numpy as np
try:
    #conf = SparkConf().setMaster('local').setAppName('autoencoder_recommender_wide_user_record_maker') # original
    #conf = SparkConf().setMaster('local').setAppName('autoencoder_recommender_wide_user_record_maker').set("spark.sql.pivotMaxValues", "99999")
    conf = SparkConf().setMaster('local').setAppName('autoencoder_recommender_wide_user_record_maker').set("spark.sql.pivotMaxValues", 99999)
    sc = SparkContext(conf=conf)
except:
    print("Variables sc and conf are now defined. Everything is OK and ready to run.")

<;。。。(其他代码)…>

^{pr2}$

在我的交叉表代码行中引发的Spark错误消息:

IllegalArgumentException: "requirement failed: The number of distinct values for itemname, can't exceed 1e4. Currently 16467"

我希望我并没有真正设置我试图设置的配置变量,那么如果可能的话,有什么方法可以让这个值实际设置呢?谢谢。在

参考文献:

Finally, you may be interested to know that there is a maximum number of values for the pivot column if none are specified. This is mainly to catch mistakes and avoid OOM situations. The config key is spark.sql.pivotMaxValues and its default is 10,000.

来源:https://databricks.com/blog/2016/02/09/reshaping-data-with-pivot-in-apache-spark.html

我更愿意向上更改配置变量,因为我已经编写了交叉表代码,它在较小的数据集上运行得很好。如果确实无法更改此配置变量,那么我的备份计划如下:

  • 关系右外部联接实现我自己的Spark crosstab,其容量比databricks提供的更高
  • scipy密集向量与手工独特的组合使用字典计算代码

Tags: and代码fromimportsqlislocalconf
1条回答
网友
1楼 · 发布于 2024-09-24 22:28:17

内核.json

此配置文件应与jupyter一起分发 ~/.ipython/kernels/pyspark/kernel.json

它包含SPARK配置,包括变量PYSPARK_SUBMIT_ARGS—将与spark-submit脚本一起使用的参数列表。在

您可以尝试将 conf spark.sql.pivotMaxValues=99999添加到上述脚本中的变量。在

PS公司 也有人试图覆盖这个变量programmatically。你也可以试试。。。在

相关问题 更多 >