简体   繁体   English

如何使用 hive 外部 hive 表创建一个空的 dataframe?

[英]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.我正在使用以下内容使用 hive 外部表创建 dataframe (spark scala)。 But the dataframe also loaded data in it.但是 dataframe 也在其中加载了数据。 I need an empty DF created using hive external table's schema.我需要一个使用 hive 外部表架构创建的空 DF。 I am using spark scala for this.我为此使用火花 scala。

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

How can I create an empty dataframe using hive external hive table?如何使用 hive 外部 hive 表创建一个空的 dataframe?

You can just do:你可以这样做:

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

This will give you the empty df with only the schema.这将为您提供仅包含架构的空 df。 Because of lazy evaluation it also does not take longer than just loading the schema.由于惰性评估,它也不会比仅仅加载模式花费更长的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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