qwerty
qwerty

Reputation: 546

Create table from SQL query in Spark (v.1.5.2)

I have a quite straightforward question, how can I create a table from an SQL query in Spark(1.5.2)?

I have seen that in the standard SQL Server 2008, this is solved the following way:

Select * into new_table  from  old_table

Is there any similar formula in Spark that does not require to use .filter() in the Dataframe?

Upvotes: 1

Views: 338

Answers (2)

Gabber
Gabber

Reputation: 7249

First save your dataframe to "old_table" table

 df.registerTempTable("old_table")

Read your old table as new dataframe

val newDF=sqlContext.sql("select * from old_table ")

Save it again to spark sql

newDF.registerTempTable("new_table")

Upvotes: 2

Sanchit Grover
Sanchit Grover

Reputation: 1008

You can use the following :

create table "database.table_name" select * from "database.table_name" where "your_condition if any"

Upvotes: 0

Related Questions