我正在使用 Jupyter 笔记本对 pySpark 进行分析。我的代码最初使用 sqlContext = SQLContext (sc) 构建数据框,但现在我已切换到HiveContext,因为我将使用窗口函数。
我的问题是,现在我在尝试创建数据框时遇到了 Java 错误:
## Create new SQL Context.
from pyspark.sql import SQLContext
from pyspark.sql import DataFrame
from pyspark.sql import Window
from pyspark.sql.types import *
import pyspark.sql.functions as func
sqlContext = HiveContext(sc)
在此之后,我将数据读入 RDD,并为我的 DF 创建模式。
## After loading the data we define the schema.
fields = [StructField(field_name, StringType(), True) for field_name in data_header]
schema = StructType(fields)
现在,当我尝试构建 DF 时,这是我得到的错误:
## Build the DF.
data_df = sqlContext.createDataFrame(data_tmp, schema)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
...
/home/scala/spark-1.6.1/python/pyspark/sql/context.pyc in _get_hive_ctx(self)
690
691 def _get_hive_ctx(self):
--> 692 return self._jvm.HiveContext(self._jsc.sc())
693
694 def refreshTable(self, tableName):
TypeError: 'JavaPackage' object is not callable
到目前为止,我一直在谷歌上搜索它,但没有运气。任何意见是极大的赞赏。