hive 和hadoop相关总结

1、表复制(五分区表复制)

create table t1 as select name,age from t2 where ds>'2022-06-04'

2、表覆盖(先清空表中的原有数据,再向表中插入数据)

insert overwrite TABLE t1  select name,age from t2 where ds>'2022-06-04'

3、表分区覆盖(先清空表分区中的原有数据,再向表中插入数据)

insert overwrite table t1 partition(ds='2019-08-08') select name,age from t2 where ds>'2022-06-04'

4、表创建:

CREATE TABLE  if not exists mydb.t1 (name string,age int) PARTITIONED BY ( `ds` string) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES ( 'field.delim'=',', 'serialization.format'=',') STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' TBLPROPERTIES ( 'bucketing_version'='2', 'transient_lastDdlTime'='1635410204');

5、表删除(慎用):DROP TABLE table_name;

6、表分区删除:ALTER TABLE example_table DROP PARTITION (date='2022-01-01');

7、表查询聚类(先聚类-再查询-再排序):select a,count(*) as frequency from mydb.t1 group by name order by frequency desc;

8、表内容和结构展示:DESCRIBE mydb.t1;

9、表详细内容和结构展示:DESCRIBE EXTENDED mydb.t1;

10、给已经存在的表插入新列:alter table mydb.t1 add columns (name string);

11、给已经存在的表级联插入新列:alter table mydb.t1 add columns (name string) cascade;

12、批量执行sql命令:hive -f mydb.sql -d mydb;

13、对表的某个字段的值进行分割后分析(爆炸分析),exploded_table表示作为扩展字段使用,explode表示将一行分解为多行

 select category1,count(1) as cnt from mytable  LATERAL VIEW explode(split(category, ',')) exploded_table AS category1 group by category1

14、对某个字段按照特定的条件进行分组:

select * from

f1,

case

when cast(substr(createtime,11,3) as float) <6 THEN '早上'

when cast(substr(createtime,11,3) as float) <12 THEN '上午'

when cast(substr(createtime,11,3) as float) <18 THEN '下午'

when cast(substr(createtime,11,3) as float) <24 THEN '晚上'

END AS action_section,

count(1) as cnt

from mytable

group by f1,action_section

14、两个字段拼接:select concat(f1,'-',f2) from tablename;

 15、 对某个字段聚合值进行字符串合并:select f1, concat_ws('###',collect_list(f2)) from mytable group by f1。 其中,collect_list是将中间结果转换为列表,collect_set是将中间结果转换为集合

大数据平台磁盘空间占用分析:

hdfs dfs -du path | awk '{SUM += $1} END {print SUM/1024*1024*1024}'

大数据路径强制删除(跳过垃圾回收):

hdfs dfs -rm -r -skipTRash path 

大数据清空回收站命令(可能由于系统时间不一致问题无法自动清空):hdfs dfs -expunge

使用sqoop从mysql同步数据到hive

sqoop import \
--connect 'jdbc:mysql://IP:PORT/database' \
--username 'username' \
--password 'pwd' \
--table myoracle.table \ -- table和--query二选一 
--query "select * from myoracle.table where 1=1 and \$CONDITIONS " \

-boundary-query  "select min(id),max(id) from myoracle.table where innercondition " \
--target-dir hive库名 \ --如果使用--table则不需要指定
 --compress \
 --compression-codec org.apache.hadoop.io.compress.SnappyCodec \

--delete-target-dir \
--fetch-size=10000 \

--hive-import \
--hive-database hivedatabase \

--hive-table userlog \
--hive-partition-key ds \
--hive-partition--value $d1 \

--hive-drop-import-delims \
 --lines-terminated-by '\n' \

--fields-terminated-by '\t' \

--hive-overwrite \ --从mysql同步到hive中时,尤其是分区更新时,使用覆盖方式避免数据重复
 --split-by id \
-m 128 --不建议太大,很费资源

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会发paper的学渣

您的鼓励和将是我前进的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值