将数据加载到pig的udf python中
我正在使用python为PIG编写一个UDF函数。我发现了一个问题,因为我需要从文件中加载一些数据来计算udf结果 我将举例说明我的想法。我的想法是编写两个函数,其中一个用于初始化:将数据加载到pig的udf python中,python,apache-pig,Python,Apache Pig,我正在使用python为PIG编写一个UDF函数。我发现了一个问题,因为我需要从文件中加载一些数据来计算udf结果 我将举例说明我的想法。我的想法是编写两个函数,其中一个用于初始化: abbr = [] def set (filename): file = open(filename, "r") for i in file: abbr.append(i) @outputSchema("out:chararray") def get (line):
abbr = []
def set (filename):
file = open(filename, "r")
for i in file:
abbr.append(i)
@outputSchema("out:chararray")
def get (line):
for i in abbr:
if line.endswith(i):
return "yes"
return "no"
我的猪脚本应该在使用“get”之前调用一次“set”。但我不知道怎么做。我还尝试使用带有构造函数的类,但我没有成功调用成员函数“get”
有人能帮我吗
更新:
我现在“解决”了一个不太漂亮的解决方案:
abbr = []
@outputSchema("out:chararray")
def get (line):
if len(abbr)==0:
file = open("file.txt", "r")
for i in file:
abbr.append(i)
for i in abbr:
if line.endswith(i):
return "yes"
return "no"