大資料之Hive DML資料操作 四

2021-10-14 15:58:42 字數 1341 閱讀 5623

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 DML資料操作 一

1.資料匯入 增 1 1.向表中裝載資料 load 0 建立一張表 hive default create table student id string,name string row format delimited fields terminated by t 1 載入本地檔案到hive hi...

大資料之Hive DML資料操作 二

資料匯入 增 3.查詢語句中建立表並載入資料 as select create table if not exists student3 as select id,name from student 4.建立表時通過location指定載入資料路徑 1 上傳資料到hdfs上 hive default...

大資料之Hive DML資料操作 七

1.排序 1 1.全域性排序 order by order by 全域性排序,只有乙個reducer 1 使用 order by 子句排序 asc ascend 公升序 預設 desc descend 降序 2 order by 子句在select語句的結尾 3 案例實操 1 查詢員工資訊按工資公升...