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