转载自:http://www.aboutyun.com/forum.php?mod=viewthread&tid=21274&extra=page%3D1
Hive从0.14版本开始支持事务和行级更新,但缺省是不支持的,需要一些附加的配置。要想支持行级insert、update、delete,需要配置Hive支持事务。
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
<
property
>
<
name
>hive.support.concurrency
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.compactor.worker.threads
name
>
<
value
>1
value
>
property
>
|
1
2
3
4
|
INSERT
INTO
NEXT_LOCK_ID
VALUES
(1);
INSERT
INTO
NEXT_COMPACTION_QUEUE_ID
VALUES
(1);
INSERT
INTO
NEXT_TXN_ID
VALUES
(1);
COMMIT
;
|
1
2
3
|
$HADOOP_HOME
/sbin/start-dfs
.sh
$HADOOP_HOME
/sbin/start-yarn
.sh
~
/mysql/bin/mysqld
&
|
1
2
3
4
|
use
test
;
create table t1(
id
int, name string)
clustered by (
id
) into 8 buckets
stored as orc TBLPROPERTIES (
'transactional'
=
'true'
);
|
1
2
3
4
|
insert
into
t1
values
(1,
'aaa'
);
insert
into
t1
values
(2,
'bbb'
);
update
t1
set
name
=
'ccc'
where
id=1;
delete
from
t1
where
id=2;
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
-- 建立非分区表并加载数据
CREATE
TABLE
t1 (id
INT
,
name
STRING, cty STRING, st STRING) ROW FORMAT DELIMITED FIELDS TERMINATED
BY
','
;
LOAD
DATA
LOCAL
INPATH
'/home/grid/a.txt'
INTO
TABLE
t1;
SELECT
*
FROM
t1;
-- 建立外部分区事务表并加载数据
CREATE
EXTERNAL
TABLE
t2 (id
INT
,
name
STRING) PARTITIONED
BY
(country STRING, state STRING)
CLUSTERED
BY
(id)
INTO
8 BUCKETS
STORED
AS
ORC TBLPROPERTIES (
'transactional'
=
'true'
);
INSERT
INTO
T2 PARTITION (country, state)
SELECT
*
FROM
T1;
SELECT
*
FROM
t2;
-- 修改数据
INSERT
INTO
TABLE
t2 PARTITION (country, state)
VALUES
(5,
'刘'
,
'DD'
,
'DD'
);
UPDATE
t2
SET
name
=
'张'
WHERE
id=1;
DELETE
FROM
t2
WHERE
name
=
'李四'
;
SELECT
*
FROM
t2;
|