为什么Zeppelin因“输入不匹配”而失败;'在%spark.sql段中期待<eof>“?

时间:2017-12-30 21:57:14

标签: apache-spark apache-spark-sql parquet apache-zeppelin

我已经从csv构建了一个镶木地板文件。

在Zeppelin中,我创建了一个sql语句,如:

%spark.sql
DROP TABLE IF EXISTS df;
CREATE TABLE df (
    date_time STRING
  , site_name STRING
  , posa_continent STRING
  , user_location_country STRING
  , user_location_region STRING
  , user_location_city STRING
  , orig_destination_distance DOUBLE
  , user_id STRING
  , is_mobile STRING
  , is_package STRING
  , channel STRING
  , srch_ci STRING
  , srch_co STRING
  , srch_adults_cnt INT 
  , srch_children_cnt INT
  , srch_rm_cnt INT
  , srch_destination_id STRING
  , srch_destination_type_id STRING
  , is_booking STRING
  , cnt INT
  , hotel_continentm STRING
  , hotel_country STRING
  , hotel_market STRING
  , hotel_cluster STRING)
USING parquet
OPTIONS (path "s3://hansprojekt/training_17000000pq")

结果我收到一个错误:

mismatched input ';' expecting <EOF>(line 1, pos 23)
== SQL ==
DROP TABLE IF EXISTS df;
-----------------------^^^
CREATE TABLE df (
    date_time STRING
  , site_name STRING
  , posa_continent STRING
  , user_location_country STRING
  , user_location_region STRING
  , user_location_city STRING
  , orig_destination_distance DOUBLE
  , user_id STRING
  , is_mobile STRING
  , is_package STRING
  , channel STRING
  , srch_ci STRING
  , srch_co STRING
  , srch_adults_cnt INT 
  , srch_children_cnt INT
  , srch_rm_cnt INT
  , srch_destination_id STRING
  , srch_destination_type_id STRING
  , is_booking STRING
  , cnt INT
  , hotel_continent STRING
  , hotel_country STRING
  , hotel_market STRING
  , hotel_cluster STRING)
USING parquet
OPTIONS (path "s3://hansprojekt/training_17000000pq")
set zeppelin.spark.sql.stacktrace = true to see full stacktrace

我不明白这个问题。 csv与','分开。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

在Zeppelin的%spark.sql中的paragraph(又名代码部分)使用一个SQL语句。

所以,这一行在一个段落中:

DROP TABLE IF EXISTS df;

和另一个%spark.sql段中的那个。

CREATE TABLE df (
    date_time STRING
  , site_name STRING
  , posa_continent STRING
  , user_location_country STRING
  , user_location_region STRING
  , user_location_city STRING
  , orig_destination_distance DOUBLE
  , user_id STRING
  , is_mobile STRING
  , is_package STRING
  , channel STRING
  , srch_ci STRING
  , srch_co STRING
  , srch_adults_cnt INT 
  , srch_children_cnt INT
  , srch_rm_cnt INT
  , srch_destination_id STRING
  , srch_destination_type_id STRING
  , is_booking STRING
  , cnt INT
  , hotel_continentm STRING
  , hotel_country STRING
  , hotel_market STRING
  , hotel_cluster STRING)
USING parquet
OPTIONS (path "s3://hansprojekt/training_17000000pq")

%spark.sql provides a SQL environment using Spark SQL(通过SparkSQLInterpreter)。

如果我 错误,请求结果SparkSQLInterpreter时只需执行SQLContext.sql

  // method signature of sqlc.sql() is changed
  // from  def sql(sqlText: String): SchemaRDD (1.2 and prior)
  // to    def sql(sqlText: String): DataFrame (1.3 and later).
  // Therefore need to use reflection to keep binary compatibility for all spark versions.
  Method sqlMethod = sqlc.getClass().getMethod("sql", String.class);
  rdd = sqlMethod.invoke(sqlc, st);

指向SQLContext.sql作为“执行环境”。

  

sql(sqlText:String):DataFrame 使用Spark执行SQL查询,将结果作为DataFrame返回。

sql需要一个SQL语句。