使用%sql时找不到表

时间:2016-04-11 21:44:11

标签: apache-zeppelin

执行%sql语句时,以下代码抛出异常如下:

  

异常 - org.apache.spark.sql.AnalysisException:找不到表:businessReviews;第1行第14页

代码:

val business_DF = sqlCtx.read.json("/Users/tom/Documents/Spring 2016/Java/Project/YELP/yelp/DS - YELP/yelp_academic_dataset_business.json").select("business_id", "categories", "state", "city", "name", "longitude", "latitude")
import sqlContext.implicits._
business_DF.registerTempTable("businessReviews")

%sql
select * from businessReviews

ZEPPELIN_SPARK_USEHIVECONTEXT set to False in zeppelin-env.sh
export ZEPPELIN_SPARK_USEHIVECONTEXT = false # Use HiveContext instead of SQLContext if set true. true by default.

2 个答案:

答案 0 :(得分:0)

以下适用于我*:

%pyspark 

business_DF = spark.read.json("/tmp/yelp_academic_dataset_business.json")
business_DF = business_DF.select("business_id", "categories", "state", "city", "name", "longitude", "latitude")
business_DF.registerTempTable("businessReviews")

%sql
select * from businessReviews
  

zeppelin screenshot

但是,出于您所描述的目的,我不会为临时表烦恼。您可以使用z.show(<dataframe>),例如:

%pyspark 

business_DF = spark.read.json("/tmp/yelp_academic_dataset_business.json")
business_DF = business_DF.select("business_id", "categories", "state", "city", "name", "longitude", "latitude")
z.show(business_DF)
  

Zeppelin screenshot 2

*使用Spark 2.0.0,Python 3.5.2和Zeppelin的快照构建(@ 04da56403b543e661dca4485f3c5a33ac53d0ede)

答案 1 :(得分:0)

在此行的开头添加:

spark = SparkSession.builder.master("yarn").enableHiveSupport().getOrCreate()

为我工作