简体   繁体   English

Hive:创建分区后使用目录分区的外部表(在 Location 中声明)

[英]Hive: Create External Table Partitioned with directory after partition (declared in Location)

I have this directory where the data are dumped:我有这个数据被转储的目录:

"/externallocation/data/20191123/foo_table/part-00000.orc"

I need to create a external table, pointed to that directory refered above.我需要创建一个外部表,指向上面提到的那个目录。
The below statement creates the table, but the query not work as expected (no record is returned):下面的语句创建了表,但查询没有按预期工作(没有返回记录):

> CREATE EXTERNAL TABLE IF NOT EXISTS foo_table (a_column string, b_column boolean)
PARTITIONED BY (year_month_day_key string)
STORED AS ORC LOCATION '/externallocation/data';

> SELECT * FROM foo_table WHERE year_month_day_key = '20191123';

Could somone now what is wrong.可有人现在有什么问题。 Thanks in advance.提前致谢。

Here is the complete solution -这是完整的解决方案 -

File already exists on the HDFS directory "/user/hive/warehouse/schema.db/foo_table/year_month_day_key=20191123/000000_0" HDFS目录下已经存在文件“/user/hive/warehouse/schema.db/foo_table/year_month_day_key=20191123/000000_0”

Now Create Table CREATE EXTERNAL TABLE IF NOT EXISTS schema.foo_table (a_column string, b_column int) PARTITIONED BY (year_month_day_key string) STORED AS ORC LOCATION 'hdfs://nameservice1/user/hive/warehouse/schema.db/foo_table';现在创建表CREATE EXTERNAL TABLE IF NOT EXISTS schema.foo_table (a_column string, b_column int) PARTITIONED BY (year_month_day_key string) STORED AS ORC LOCATION 'hdfs://nameservice1/user/hive/warehouse/schema.db/foo_table';

Partition needs to be added after table creation through below Alter command ALTER TABLE schema.foo_table ADD PARTITION (year_month_day_key = '20191123');创建表后需要通过以下 Alter 命令添加分区 ALTER TABLE schema.foo_table ADD PARTITION (year_month_day_key = '20191123');

select * from schema.foo_table where year_month_day_key = '20191123'; select * from schema.foo_table where year_month_day_key = '20191123';

select * from schema.foo_table; select * from schema.foo_table;

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

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