Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to save results from dataframe into a separate hive table

Solved Go to solution

How to save results from dataframe into a separate hive table

I have got the following:

val df = sqlContext.sql("SELECT * from table1")
var tempResult = df.filter(df("field1") > 10)

I have also already created another table - table2 - with the same structure as table1.

How can I save/insert the result of tempResult into table2?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to save results from dataframe into a separate hive table

OK - I get this working now. If anyone interested, here you are:

val df = sqlContext.sql("SELECT * from table1")
val tempResult = df.filter(df("field1") > 10)
tempResult.write.mode("overwrite").saveAsTable("default.new_table")
val df1 = sqlContext.sql("SELECT * from default.new_table")
df1.show()

NOTE: the "new_table" table can but does not need to exist before writing to it

1 REPLY 1
Highlighted

Re: How to save results from dataframe into a separate hive table

OK - I get this working now. If anyone interested, here you are:

val df = sqlContext.sql("SELECT * from table1")
val tempResult = df.filter(df("field1") > 10)
tempResult.write.mode("overwrite").saveAsTable("default.new_table")
val df1 = sqlContext.sql("SELECT * from default.new_table")
df1.show()

NOTE: the "new_table" table can but does not need to exist before writing to it