Update Hive常用DML操作.md

This commit is contained in:
heibaiying 2019-04-29 17:24:22 +08:00 committed by GitHub
parent 2c37679b55
commit aaff08d791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,11 +75,11 @@ LOAD DATA INPATH "hdfs://hadoop001:8020/mydir/emp.txt" OVERWRITE INTO TABLE emp
### 2.1 语法
```sql
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)
[IF NOT EXISTS]] select_statement1 FROM from_statement;
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) [IF NOT EXISTS]]
select_statement1 FROM from_statement;
INSERT INTO TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)]
select_statement1 FROM from_statement;
select_statement1 FROM from_statement;
```
+ Hive 0.13.0开始建表时可以通过使用TBLPROPERTIES“immutable”=“true”来创建不可变表(immutable table) 如果不可以变表中存在数据则INSERT INTO失败。INSERT OVERWRITE的语句不受`immutable`属性的影响);
@ -210,40 +210,39 @@ DELETE FROM tablename [WHERE expression]
1. 首先需要更改`hive-site.xml`添加如下配置开启事务支持配置完成后需要重启Hive服务。
```xml
<property>
<name>hive.support.concurrency</name>
<value>true</value>
</property>
<property>
<name>hive.enforce.bucketing</name>
<value>true</value>
</property>
<property>
<name>hive.exec.dynamic.partition.mode</name>
<value>nonstrict</value>
</property>
<property>
<name>hive.txn.manager</name>
<value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
</property>
<property>
<name>hive.compactor.initiator.on</name>
<value>true</value>
</property>
<property>
<name>hive.in.test</name>
<value>true</value>
</property>
```
```xml
<property>
<name>hive.support.concurrency</name>
<value>true</value>
</property>
<property>
<name>hive.enforce.bucketing</name>
<value>true</value>
</property>
<property>
<name>hive.exec.dynamic.partition.mode</name>
<value>nonstrict</value>
</property>
<property>
<name>hive.txn.manager</name>
<value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
</property>
<property>
<name>hive.compactor.initiator.on</name>
<value>true</value>
</property>
<property>
<name>hive.in.test</name>
<value>true</value>
</property>
```
2. 创建用于测试的事务表,建表时候指定属性`transactional = true`则代表该表是事务表。需要注意的是,按照[官方文档](https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions)的说明目前Hive中的事务表有以下限制
+ 必须是buckets Table;
+ 仅支持ORC文件格式
+ 不支持LOAD DATA ...语句。
+ 不支持LOAD DATA ...语句。
```sql
-- 建表语句
CREATE TABLE emp_ts(
empno int,
ename String
@ -327,4 +326,4 @@ SELECT * FROM emp_ptn;
## 参考资料
1. [Hive Transactions](https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions)
2. [Hive Data Manipulation Language](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML)
2. [Hive Data Manipulation Language](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML)