pyspark AttributeError: 'NoneType' object has no attribute 'setCallSite'
pyspark:
AttributeError: 'NoneType' object has no attribute 'setCallSite'
我草,是pyspark的bug。解决方法:
print("Approximately joining on distance smaller than 0.6:")
distance_min = model.approxSimilarityJoin(imsi_proc_df, imsi_proc_df, 1e6, distCol="JaccardDistance") \
.select(col("datasetA.id").alias("idA"),
col("datasetB.id").alias("idB"),
col("JaccardDistance")) #.filter("idA=idB")
print(distance_min.show())
print("*"*88)
print(imsi_proc_df.show())
key = Vectors.sparse(53, [1, 3], [1.0, 1.0])
print(model.approxNearestNeighbors(imsi_proc_df, key, 2).show())
print("start calculate find botnet!")
print("*"*99)
print("time start:", time.time())
print(type(distance_min), dir(distance_min))
print(dir(distance_min.toLocalIterator))
############################################## add this line to solve
distance_min.sql_ctx.sparkSession._jsparkSession = spark_app._jsparkSession
distance_min._sc = spark_app._sc
#############################################
similarity_val_rdd = distance_min.toLocalIterator #.collect()
print("time end:", time.time())
print(similarity_val_rdd)
print("*"*99)
try:
G = ConnectedGraph()
ddos_ue_list = []
for item in similarity_val_rdd():
imsi, imsi2, jacard_similarity_val = item["idA"], item["idB"], item["JaccardDistance"]
print("???", imsi, imsi2, jacard_similarity_val)
Description
reproducing the bug from the example in the documentation:
import pyspark
from pyspark.ml.linalg import Vectors
from pyspark.ml.stat import Correlation
spark = pyspark.sql.SparkSession.builder.getOrCreate()
dataset = [[Vectors.dense([1, 0, 0, -2])],
[Vectors.dense([4, 5, 0, 3])],
[Vectors.dense([6, 7, 0, 8])],
[Vectors.dense([9, 0, 0, 1])]]
dataset = spark.createDataFrame(dataset, ['features'])
df = Correlation.corr(dataset, 'features', 'pearson')
df.collect()
This produces the following stack trace:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-92-e7889fa5d198> in <module>()
11 dataset = spark.createDataFrame(dataset, ['features'])
12 df = Correlation.corr(dataset, 'features', 'pearson')
---> 13 df.collect() /opt/spark/python/pyspark/sql/dataframe.py in collect(self)
530 [Row(age=2, name=u'Alice'), Row(age=5, name=u'Bob')]
531 """
--> 532 with SCCallSiteSync(self._sc) as css:
533 sock_info = self._jdf.collectToPython()
534 return list(_load_from_socket(sock_info, BatchedSerializer(PickleSerializer()))) /opt/spark/python/pyspark/traceback_utils.py in __enter__(self)
70 def __enter__(self):
71 if SCCallSiteSync._spark_stack_depth == 0:
---> 72 self._context._jsc.setCallSite(self._call_site)
73 SCCallSiteSync._spark_stack_depth += 1
74 AttributeError: 'NoneType' object has no attribute 'setCallSite'
Analysis:
Somehow the dataframe properties `df.sql_ctx.sparkSession._jsparkSession`, and `spark._jsparkSession` do not match with the ones available in the spark session.
The following code fixes the problem (I hope this helps you narrowing down the root cause)
df.sql_ctx.sparkSession._jsparkSession = spark._jsparkSession
df._sc = spark._sc df.collect() >>> [Row(pearson(features)=DenseMatrix(4, 4, [1.0, 0.0556, nan, 0.4005, 0.0556, 1.0, nan, 0.9136, nan, nan, 1.0, nan, 0.4005, 0.9136, nan, 1.0], False))]
pyspark AttributeError: 'NoneType' object has no attribute 'setCallSite'的更多相关文章
- python3 AttributeError: 'NoneType' object has no attribute 'split'
from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...
- AttributeError: 'NoneType' object has no attribute 'split' 报错处理
报错场景 social_django 组件对原生 django 的支持较好, 但是因为 在此DRF进行的验证为 JWT 方式 和 django 的验证存在区别, 因此需要进行更改自行支持 JWT 方式 ...
- python提示AttributeError: 'NoneType' object has no attribute 'append'【转发】
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
- python提示AttributeError: 'NoneType' object has no attribute 'append'
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
- Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'
问题说明: 首先呢,报这个错误的代码是这行代码: model = Model(inputs=input, outputs=output) 报错: AttributeError 'NoneType' o ...
- AttributeError: 'NoneType' object has no attribute 'extend'
Python使用中可能遇到的小问题 AttributeError: 'NoneType' object has no attribute 'extend' 或者AttributeError: 'Non ...
- 解决opencv:AttributeError: 'NoneType' object has no attribute 'copy'
情况一: 路径中有中文,更改即可 情况二:可以运行代码,在运行结束时显示 AttributeError: 'NoneType' object has no attribute 'copy' 因为如果是 ...
- appium 报错:AttributeError:"NoneType' object has no attribute 'XXX'
报错截图如下: 问题原因: 根据以上报错提示可已看到问题的原因为:logger中没有info此方法的调用,点击"具体报错的位置"上面的链接,可直接定位到具体的报错位置.根据分析所得 ...
- PIL中分离通道发生“AttributeError: 'NoneType' object has no attribute 'bands'”
解决方法: 这个貌似是属于一个bug 把Image.py中的1500行左右的split函数改成如下即可: def split(self): "Split image into bands&q ...
随机推荐
- 【Tools】HP/惠普v285w 量产工具
前段时间朋友说自己u盘坏了,让帮忙看看.看下图是这个u盘. 坏的问题:往里面复制东西,提示:请去掉写保护或使用另一张磁盘.但是能正常从里面读取出来数据. 无论更换电脑,还是使用网上的修改注册表等方式皆 ...
- VS2013+OpenCV3.4.2编译
一.准备工作: (1)在OpenCV官网下载3.4.2版本(注意选择Win pack),https://opencv.org/releases.html. (2)下载Contrib模块,https:/ ...
- servlet 标红的错误笔记
错误原因,没有添加来自Tomcat服务器的jar包依赖. 解决方法
- SpringBoot读取properties中的属性值
1.在application.properties中添加以下内容: learn.blog.name=hello learn.blog.title=千回教育系统 2.新增属性关联的类: package ...
- Springboot采用hibernate-validate验证请求参数
在springboot项目使用hibernate-validate对请求参数添加注解进行校验 常用注解 @Null,标注的属性值必须为空 @NotNull,标注的属性值不能为空 @AssertTrue ...
- 超实用的 JavaScript 代码片段( ES6+ 编写)
Array 数组 Array concatenation (数组拼接) 使用 Array.concat() ,通过在 args 中附加任何数组 和/或 值来拼接一个数组. const ArrayCon ...
- Python开发之规范化目录
13.规范化目录 规范目录优点: 可读性高 加载快 查询修改简 规范化目录结构 (1) start.py文件:首要配置启动文件,运行run()就可以执行项目 #start import sys imp ...
- 通过Anaconda安装的jupyter notebook,打开时,未能启动默认浏览器
问题:通过Anaconda安装的jupyter notebook,通过开始菜单的快捷方式打开时,未能启动网页,需要复制url,粘贴到浏览器中才会出现工作面板. 解决方法: 修改jupyter_note ...
- 【flask】登陆后返回之前重定向跳转的页面
登陆后返回之前重定向跳转的页面 一.前言 实现强制跳转到登陆页面,登陆后返回之前的页面的功能.网上跳登陆页面的很多:返回之前页面功能没多少.这里我只是用了自己的方法,有缺点和其他方法也请指点!(´ε` ...
- SpringCloudConfig相关配置简介、使用、整合Eureka
目的: 1.SpringCloud Config简介 2.Config Server基本使用 3.Config Client基本使用 4.Config整合Eureka 5.Config配置搜索路径 S ...