像 dataframe.show() 、 sqlContext.read.json 这样的操作工作正常,但大多数函数都会给出“JavaPackage object is not callable error”。
例如:当我这样做时
dataFrame.withColumn(field_name, monotonically_increasing_id())
我收到一个错误
File "/tmp/spark-cd423f35-9572-45ee-b159-1b2732afa2a6/userFiles-3a6e1729-95f4-468b-914c-c706369bf2a6/Transformations.py", line 64, in add_id_column
self.dataFrame = self.dataFrame.withColumn(field_name, monotonically_increasing_id())
File "/home/himaprasoon/apps/spark-1.6.0-bin-hadoop2.6/python/pyspark/sql/functions.py", line 347, in monotonically_increasing_id
return Column(sc._jvm.functions.monotonically_increasing_id())
TypeError: 'JavaPackage' object is not callable
我正在使用 apache-zeppelin 解释器,并将 py4j 添加到 python 路径。
当我做
import py4j
print(dir(py4j))
导入成功
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'compat', 'finalizer', 'java_collections', 'java_gateway', 'protocol', 'version']
当我尝试时
print(sc._jvm.functions)
在 pyspark shell 中打印
<py4j.java_gateway.JavaClass object at 0x7fdaf9727ba8>
但是当我在解释器中尝试这个时,它会打印
<py4j.java_gateway.JavaPackage object at 0x7f07cc3f77f0>