【问题标题】:Spark-submit Sql Context Create Statement does not workSpark-submit Sql Context Create Statement 不起作用
【发布时间】:2015-08-17 18:00:57
【问题描述】:

我下面的代码不适用于 Spark-submit。

sqlContext.sql(s"""
create external table if not exists landing (
date string,
referrer string)
partitioned by (partnerid string,dt string)
row format delimited fields terminated by '\t' lines terminated by '\n'
STORED AS TEXTFILE LOCATION 's3n://....'
      """)

它给出了错误: 线程“主”java.lang.RuntimeException 中的异常:[1.2] 失败:预期“带有”,但发现标识符创建

此代码在 Spark-shell 中有效,但在 Spark-submit 中无效。可能是什么原因?

【问题讨论】:

  • 可能缺少导入?
  • 还有import sqlContext.implicits._?
  • class Analysis extends Serializable{ val sc = new SparkContext() val sqlContext = SQLContextSingleton.getInstance(sc) import sqlContext.implicits._ => 我这样运行但没办法:(
  • 您最终找到解决方案了吗?

标签: scala apache-spark spark-streaming apache-spark-sql


【解决方案1】:

spark-shell 中的“sqlContext”默认为“HiveContext”。也许您需要在脚本中新建一个 HiveContext 而不是 sqlContext。

你可以这样新建它:

import SparkContext._
import org.apache.spark.sql.hive._ 
val sc = new SparkContext()
val sqlContext = new HiveContext(sc)

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 2015-04-28
    • 2016-04-18
    相关资源
    最近更新 更多