已定义全局变量的文件:
# Globals.py--
def init():
global XYZ
XYZ='Some Variable'
print("GLobal Variables initialized Successfully ")
这是试图访问“xyz”全局变量的udf函数
import Globals
# udfs.py
def trans_thrp_cd():
try:
global xyz
print(xyz)
except Exception as e:
print("Error in fetching value from the globals "+ str(e))
# main.py
import Globals
spark and other modules import-initialization
register functions as pyspark-hive UDFs
df=hive_context.sql("select trans_thrp_cd from test.people")
df.show()
获取以下提到的错误:
# Error
module 'Globals' has no attribute 'XYZ'
1条答案
按热度按时间ktecyv1j1#
在globals.py中:
在udfs.py中: