Hive

[Hive] Hive 3버전 특징

heed159 2022. 4. 19. 17:11

Hive 버전 3가 되면서 기존과 같이 TEXTFILE, SEQUENCEFILE, AVRO, ORC 등 여러가지 타입을 지원하지만 Hive Table은 기본적으로 Transactional 속성을 갖는다.

이는 Managed Table 및 ORC 타입 한정으로 UPDATE 및 DELETE 쿼리가 가능해진다.

 

 

직접 확인해보자.

 

{테이블 : External Table, 타입 : TEXTFILE}

hive> create external table t1 (col1 int, col2 int)
    > stored as textfile;
OK
Time taken: 0.77 seconds
hive> insert into t1 values (1, 2);

hive> update t1 set col1 = 3 where col1 = 1;
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

 

 

{테이블 : External Table, 타입 : ORC}

hive> create external table t2 (col1 int, col2 int)
    > stored as orc;
OK
Time taken: 0.158 seconds
hive> insert into t2 values (3, 4);

hive> update t2 set col1 = 1 where col1 = 3;
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

 

 

{테이블 : Managed Table, 타입 : TEXTFILE}

hive> create table t3 (col1 int, col2 int)
    > stored as textfile;
OK
Time taken: 0.203 seconds
hive> insert into t3 values (1, 2);

hive> update t3 set col1 = 3 where col1 = 1;
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

 

 

{테이블 : Managed Table, 타입 : ORC}

hive> create table t4 (col1 int, col2 int)
    > stored as orc;
OK
Time taken: 0.203 seconds
hive> insert into t3 values (3, 4);

hive> update t3 set col1 = 1 where col1 = 3;
.
.
OK
hive> select * from t4;
OK
+----------+----------+
| t4.col1  | t4.col2  |
+----------+----------+
| 1        | 4        |
+----------+----------+

 

 

 


 

 

 

테스트를 해보니 3버전이라도 UPDATE, DELETE 쿼리를 수행하려면 추가 설정이 필요했다.

 

<hive-site.xml>

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    	    .
            .
            .
	<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>
       <property>
           <name>hive.support.concurrency</name>
           <value>true</value>
       </property>
</configuration>

 

 

위의 네 가지 설정을 완료해준 뒤에 Table을 생성해도 UPDATE가 되지 않아서 좀 더 찾아보니 테이블을 생성할 때 transactional = true 옵션을 주면 가능했다.

 

hive> create table t5 (col1 int, col2 int)
    > stored as orc tblproperties('transactional'='true');
OK

 

회사 서버에 내가 구축한 Hadoop Cluster 내에 올라와 있는 hive에서는 위처럼 테이블 생성 시 transactional 옵션을 주어야 하지만 다른 서버에 구축된 환경에서의 hive는 해당 옵션을 주지 않고도 바로 UPDATE, DELETE 쿼리가 가능했다. hive-site.xml 에서 설정해주었던 것처럼 다른 설정파일에서 default?로 설정이 가능할 것 같은데 더 찾아봐야 할 것 같다.