Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark-submit Sql Context Create Statement does not work

My below code does not work with 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://....'
      """)

It gives error: Exception in thread "main" java.lang.RuntimeException: [1.2] failure: ``with'' expected but identifier create found

This code works in Spark-shell but not in Spark-submit. What can be the reason?

like image 255
Yusuf Can Gürkan Avatar asked Oct 19 '22 04:10

Yusuf Can Gürkan


1 Answers

"sqlContext" in spark-shell is 'HiveContext' by default. Maybe you need to new a HiveContext instead of sqlContext in your script.

You may new it like that:

import SparkContext._
import org.apache.spark.sql.hive._ 
val sc = new SparkContext()
val sqlContext = new HiveContext(sc)
like image 190
中国人威 Avatar answered Oct 21 '22 22:10

中国人威