1
我想创建一个外部HIVE表,该表利用HDFS中已有的数据。这些文件位于/hdfs/data/location
和year-month
格式的子目录中。例如:/hdfs/data/location/2013-december
和/hdfs/data/location/2014-january
。从不同记录格式的文件创建外部HIVE表
这些目录内有多个文件,但文件内是不同类型的数据(不同的字段)。不同类型的记录的实例是:
A型
type
state
city
population
类型B
type
zipcode
registeredvoters
实际数据的例子(制表符分隔)
type:A state:New York city:New York population:8336697
type:A state:California city:Los Angeles population:3857799
type:B zipcode:92118 registeredvoters:794051
type:B zipcode:92155 registeredvoters:794053
type:A state:Illinois city:Chicago population:2714856
的数据是已经在这种格式并被HIVE以外的其他进程使用,所以改变它可能不是一种选择。我也不想在HDFS中复制数据。
有没有一种方法可以为上述数据中定义的给定类型创建一个HIVE表?
这里是我迄今为止的创造:
create external table population (
type string,
state string,
city string,
population int
)
location '/hdfs/data/location';
我还需要where type ='A',因为type ='B'没有这些列吗? –
您可以添加其他类型的其他列(即pmap ['zipcode'],pmap ['population']),如果该值不在地图中,它应该返回null。 或者您可以添加“pmap ['type'] ='A'” –