使用IDEA,安装了python插件,在Maven工程中使用pyspark。
执行下面这段代码的时候报错
# -*- encoding: utf-8 -*-
"""
Created on 16:07 2019/4/9
@author: fancyChuan
@email: 1247375074@qq.com
@desc: 向spark传递函数 示例
"""
from pyspark import SparkConf, SparkContext
class SearchFunctionsWarn(object):
"""
不推荐的写法,rdd.filter()传递函数的时候会把整个self都传递到集群上,可能self非常大
"""
def __init__(self, query):
self.query = query
def isMatch(self, s):
return self.query in s
def getMatchesFunctionReference(self, rdd):
return rdd.filter(self.isMathch) # 有风险
def getMatchesMemberReference(self, rdd):
return rdd.filter(self.isMatch) # 有风险
class SearchFunctionsRight(object):
"""
推荐的写法,使用局部变量,把需要传递的内容赋值给局部变量,然后传递局部变量
结论: 传递局部可序列化变量或者顶层函数始终是安全
"""
def __init__(self, query):
self.query = query
def isMatch(self, s):
return self.query in s
def getMatchesFunctionReference(self, rdd):

在IDEA的Maven工程中使用pyspark时遇到 '_PYSPARK_DRIVER_CONN_INFO_PATH' 错误,原因是maven工程的spark版本与本地安装的spark版本不匹配。解决方案包括检查并统一maven、本地及pyspark包的spark版本,以及在代码更新后重新导入maven依赖或重启IDEA。
最低0.47元/天 解锁文章
8464

被折叠的 条评论
为什么被折叠?



