I am trying to insert a dataframe into a Hive table using the following code:
import org.apache.spark.sql.SaveMode
import org.apache.spark.sql._
val hiveCont = val hiveCont = new org.apache.spark.sql.hive.HiveContext(sc)
val empfile = sc.textFile("empfile")
val empdata = empfile.map(p => p.split(","))
case class empc(id:Int, name:String, salary:Int, dept:String, location:String)
val empRDD = empdata.map(p => empc(p(0).toInt, p(1), p(2).toInt, p(3), p(4)))
val empDF = empRDD.toDF()
empDF.registerTempTable("emptab")
I have a table in Hive with following DDL:
# col_name data_type comment
id int
name string
salary int
dept string
# Partition Information
# col_name data_type comment
location string
I'm trying to insert the temporary table into the hive table as follows:
hiveCont.sql("insert into parttab select id, name, salary, dept from emptab")
This is giving an exception:
org.apache.spark.sql.AnalysisException: Table not found: emptab. 'emptab' is the temp table created from Dataframe
Here I understand that the hivecontext will run the query on 'HIVE' from Spark and it doesn't find the table there, hence resulting exception. But I don't understand how I can fix this issue. Could any tell me how to fix this ?