refer:https://blog.csdn.net/longshenlmj/article/details/51702343
#Hive建外部External表(外部表external table):
CREATE EXTERNAL TABLE `table_name`(
? `column1` string,
? `column2` string,
? `column3` string)
PARTITIONED BY (
? `proc_date` string)
ROW FORMAT SERDE?
? ?'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
STORED AS INPUTFORMAT?
? ?'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
? ?'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
? 'hdfs://hdfscluster/...'
TBLPROPERTIES ( 'orc.compress'='snappy');#
#
#添加分區(qū)并加載分區(qū)數(shù)據(jù):
alter table table_name add partition (proc_date='${hivevar:pdate}')?location '...'(不改變源數(shù)據(jù)存儲位置)
alter table table_name add if not exsit partition (proc_date='${hivevar:pdate}')?location 'hdfs://hdfscluster/'
load data inpath '...' into table table_name partition(proc_date='${hivevar:pdate}');(會將源數(shù)據(jù)切到hive表指定的路徑下)
#刪除分區(qū):alter table table_name drop if exists partition(proc_date='${hivevar:pdate}');
#TBLPROPERTIES
實際上就是table properties,TBLPROPERTIES允許開發(fā)者定義一些自己的鍵值對信息±觯可以對TBLPROPERTIES進(jìn)行查看和修改(部分可修改)。在TBLPROPERTIES中有一些預(yù)定義信息,比如last_modified_user和last_modified_time,其他的一些預(yù)定義信息包括:
TBLPROPERTIES ("comment"="table_comment")
TBLPROPERTIES ("hbase.table.name"="table_name")
TBLPROPERTIES ("immutable"="true") or ("immutable"="false")
TBLPROPERTIES ("orc.compress"="ZLIB") or ("orc.compress"="SNAPPY") or ("orc.compress"="NONE")
TBLPROPERTIES ("transactional"="true") or ("transactional"="false")
TBLPROPERTIES ("NO_AUTO_COMPACTION"="true") or ("NO_AUTO_COMPACTION"="false"), the default is "false"
TBLPROPERTIES ("compactor.mapreduce.map.memory.mb"="mapper_memory")
TBLPROPERTIES ("compactorthreshold.hive.compactor.delta.num.threshold"="threshold_num")
TBLPROPERTIES ("compactorthreshold.hive.compactor.delta.pct.threshold"="threshold_pct")
TBLPROPERTIES ("auto.purge"="true") or ("auto.purge"="false")
TBLPROPERTIES ("EXTERNAL"="TRUE")
#
#tplproperties屬性參考
(1)comment:可以用來定義表的描述信息荣暮。
(2)hbase.table.name:hive通過 storage handler(暫放)將hive與各種工具聯(lián)系起來窍株,這是是使用hive接入hbase時,設(shè)置的屬性(暫放)解滓。
(3)immutable:顧名思義‘不可變的’,當(dāng)表的這個屬性為true時筝家,若表中無數(shù)據(jù)時可以insert數(shù)據(jù)洼裤,但是當(dāng)表已經(jīng)有數(shù)據(jù)時,insert操作會失敗溪王。不可變表用來防止意外更新腮鞍,避免因腳本錯誤導(dǎo)致的多次更新,而沒有報錯在扰。本人實際中還沒用到這個屬性缕减。
(4)orc.compress:這是orc存儲格式表的一個屬性,用來指定orc存儲的壓縮方式(暫放)芒珠。
(5) transactional桥狡,NO_AUTO_COMPACTION,compactor.mapreduce.map.memory.mb,compactorthreshold.hive.compactor.delta.num.threshold裹芝,compactorthreshold.hive.compactor.delta.pct.threshold:這5個屬性與hive的事務(wù)支持有關(guān)部逮,先不做了解。
(6)auto.purge:當(dāng)設(shè)置為ture時嫂易,刪除或者覆蓋的數(shù)據(jù)會不經(jīng)過回收站兄朋,直接被刪除。配置了此屬性會影響到這些操作: Drop Table, Drop Partitions, Truncate Table,Insert Overwrite怜械。
(7)EXTERNAL:通過修改此屬性可以實現(xiàn)內(nèi)部表和外部表的轉(zhuǎn)化颅和。
#