现在的位置: 首页 > 综合 > 正文

hive学习 hive中的表

2019年05月24日 ⁄ 综合 ⁄ 共 1307字 ⁄ 字号 评论关闭
stored   as  存储格式(testfile/sequencefile/rcfile)

hive中的表分为内部表和外部表,内部表认为是数据完整的,删除表时也会删除表的数据,而外部表不会删除表的数据,只会删除表的元数据。

怎么创建一个外部表:

create   <span style="color:#FF0000;">external </span>  table   表名 (参数) 
raw   format   delimited   fields    terminated   by  ‘,’//指定数据的解析分隔符
location   ‘数据的位置(如果在hdfs上,则天蝎hdfs的位置)’   


分区表(优化性能):

怎么创建一个分区表:

create   table    表名 (参数) partitioned  by(country  string,  state  string);  其中:country,state也算是表的字段,如果用户在表的字段中
有与之重复的字段,则会被忽略

在hive中,mapred任务是触发提交的,当任务巨大是就会触发 

在进行分区表查询是,建议设置:hive.mapred.mode=strict 模式,这样当有没有添加where的分区表查询时,会倍禁止提交。

怎么创建一个外部分区表:

create  external  table 表名(列名)
partitioned by(分区属性)
row formate delimited  fields   terminated  by ‘分隔符’

外部表怎么加入数据:

alter    table     xxx   add partition(xx=xx) location ‘数据位置’

如果想修改指向的路径:

alter    table     xxx   add partition(xx=xx) 
set  location  ‘数据位置’

怎么察看表中的分区:

show   partitions   表名;
describe      extended   表名

察看某个特定的分区是否存在:

show  partitions  表名  partition(xxx=xxx)

怎么将数据存入分区表:

load  data  local  inpath‘数据目录’ 
into  table  表名
partition(xxx=xxx);

怎么指定表中数据的存储格式:

stored    as  存储格式(textfile/sequencefile/rcfile)


怎么重命名表:

alter   table    表名  rename  to   新名字

怎么删除分区:

alter  table   表名  drop   partition(xx=xx)

怎么对表中的数据进行修改:

alter  table  表名    change column xxx INT  after xxx;将列xxx移动到xxx之后

怎么增加列:

alter  table  表名   add  column (app-name    string)

怎么删除和替换:

alter   table  表名  replace   column (xxxx  数据类型) 

怎么修改存储属性:

alter  table  表名  
set   serde   ‘com.example.xxx’
with   serdeproperties('key1'='value1','key2'='value2');

怎么出发钩子(不懂,带研究):

alter  table   xxxx  touch    
partition(xxx=xxx)

怎么自定义数据格式,在之后介绍

抱歉!评论已关闭.