简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM