Santhosh Chakka
Santhosh Chakka

Reputation: 335

How to create an empty dataframe using hive external hive table?

I am using the below to create a dataframe (spark scala) using hive external table. But the dataframe also loaded data in it. I need an empty DF created using hive external table's schema. I am using spark scala for this.

val table1 = sqlContext.table("db.table")

How can I create an empty dataframe using hive external hive table?

Upvotes: 1

Views: 645

Answers (1)

Paul
Paul

Reputation: 1174

You can just do:

val table1 = sqlContext.table("db.table").limit(0)

This will give you the empty df with only the schema. Because of lazy evaluation it also does not take longer than just loading the schema.

Upvotes: 2

Related Questions