大数据之Hive:DML数据操作(四)

1.查询(查)
1-1.全表查询

hive (default)> select * from emp;

1-2.选择特定列查询

hive (default)> select empno, ename from emp;

2.删除和更改
删除

delete from stu where id=1;

修改

update stu set name=zhangsan where id = 1;

特别注意:
如果一个表要实现update和delete功能,该表就必须支持ACID,而支持ACID,就必须满足以下条件:
1、表的存储格式必须是ORC(STORED AS ORC);
2、表必须进行分桶(CLUSTERED BY (col_name, col_name, …) INTO num_buckets BUCKETS);
3、Table property中参数transactional必须设定为True(tblproperties(‘transactional’=‘true’));
4、以下配置项必须被设定:
Client端:
hive.support.concurrency – true
hive.enforce.bucketing – true
hive.exec.dynamic.partition.mode – nonstrict
hive.txn.manager – org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
服务端:
hive.compactor.initiator.on – true
hive.compactor.worker.threads – 1
hive.txn.manager – org.apache.hadoop.hive.ql.lockmgr.DbTxnManager(经过测试,服务端也需要设定该配置项)
3.列别名
紧跟列名,也可以在列名和别名之间加入关键字‘AS’

hive (default)> select ename AS name, deptno dn from emp;

4.算术运算符
在这里插入图片描述

hive (default)> select sal +1 from emp;

猜你喜欢

转载自blog.csdn.net/weixin_43597208/article/details/112563382