为什么 hive 在使用分区时不能 select 来自 hdfs 的数据?
why hive can‘t select data from hdfs when use partition?
我用flume写数据到hdfs,路径像/hive/logs/dt=20151002
。然后,我用hive写select数据,但是响应的计数总是0。
这是我的创作 table sql,CREATE EXTERNAL TABLE IF NOT EXISTS test (id STRING) partitioned by (dt string) ROW FORMAT DELIMITED fields terminated by '\t' lines terminated by '\n' STORED AS TEXTFILE LOCATION '/hive/logs'
这是我的 select sql,select count(*) from test
您似乎没有在配置单元元存储中注册分区。
虽然分区存在于 hdfs 路径中,但如果它未在元存储中注册,Hive 将不知道。要注册它,您可以执行以下操作:
ALTER TABLE test ADD PARTITION (dt='20151002') location '/hive/logs/dt=20151002';
我用flume写数据到hdfs,路径像/hive/logs/dt=20151002
。然后,我用hive写select数据,但是响应的计数总是0。
这是我的创作 table sql,CREATE EXTERNAL TABLE IF NOT EXISTS test (id STRING) partitioned by (dt string) ROW FORMAT DELIMITED fields terminated by '\t' lines terminated by '\n' STORED AS TEXTFILE LOCATION '/hive/logs'
这是我的 select sql,select count(*) from test
您似乎没有在配置单元元存储中注册分区。 虽然分区存在于 hdfs 路径中,但如果它未在元存储中注册,Hive 将不知道。要注册它,您可以执行以下操作:
ALTER TABLE test ADD PARTITION (dt='20151002') location '/hive/logs/dt=20151002';