CREATE EXTERNAL TABLE test_db.`order`( `id` bigint , `pay_id` string , `order_id` bigint , `settle_id` bigint , `original_order_id` bigint , `order_type` string ) PARTITIONED BY ( `dt` string, `hour` string) ROW FORMAT SERDE ‘org.openx.data.jsonserde.JsonSerDe‘ WITH SERDEPROPERTIES ( ‘ignore.malformed.json‘=‘true‘) STORED AS INPUTFORMAT ‘org.apache.hadoop.mapred.TextInputFormat‘ OUTPUTFORMAT ‘org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat‘
DESCRIBE FORMATTED test_db.`order`;
Location: hdfs://emr-cluster/user/hive/warehouse/test_db.db/order Table Type: EXTERNAL_TABLE
ALTER TABLE test_db.`order` ADD IF NOT EXISTS PARTITION (dt = ‘2020-04-18‘, hour = ‘08‘) LOCATION ‘oss://datalake/order/dt=2020-04-18/hour=08‘ ; ALTER TABLE test_db.`order` ADD IF NOT EXISTS PARTITION (dt = ‘2020-04-18‘, hour = ‘14‘) LOCATION ‘hdfs://emr-cluster/user/hive/warehouse/test_db.db/order/dt=2020-04-18/hour=14‘ ;
select * from test_db.`order` where dt = ‘2020-04-18‘ and hour = ‘08‘; select * from test_db.`order` where dt = ‘2020-04-18‘ and hour = ‘14‘;
CREATE EXTERNAL TABLE test_db.`order`( `id` bigint , `pay_id` string , `order_id` bigint , `settle_id` bigint , `original_order_id` bigint , `order_type` string ) PARTITIONED BY ( `dt` string, `hour` string) ROW FORMAT SERDE ‘org.openx.data.jsonserde.JsonSerDe‘ WITH SERDEPROPERTIES ( ‘ignore.malformed.json‘=‘true‘) STORED AS INPUTFORMAT ‘org.apache.hadoop.mapred.TextInputFormat‘ OUTPUTFORMAT ‘org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat‘ LOCATION ‘oss://datalake/test‘
ALTER TABLE test_db.`order` ADD IF NOT EXISTS PARTITION (dt = ‘2020-04-18‘, hour = ‘08‘) LOCATION ‘oss://datalake/order/dt=2020-04-18/hour=08‘ ; select * from test_db.`order` where dt = ‘2020-04-18‘ and hour = ‘08‘;
从实践结果来看,在跨越地址根目录进行数据查询的情况下,此方案仍然可行。
原文:https://www.cnblogs.com/eric-ln/p/12746498.html