ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Hive] Hive에서 Transaction이란?(component, 제약조건, delta폴더, staging 폴더, insert, update, delete)
    데이터 엔지니어링/Hive 2022. 10. 11. 22:32
    반응형

    Transaction이란?

    SQL 질의 문 INSERT/UPDATE/DELETE/MERGE문을 이용하여 데이터의 변화를 일으키는 행위를 말한다.

     

    Transaction compoenet

    Transaction 구성 요소는 ACID라고 하는 속성이 있다. 이 말을 요약하자면, 데이터가 틀리지 않고 유지 되어야 한다는 뜻이 된다. 즉, update, delete했는데 이상하게 반영되지 않아야 한다는 것으로 이해 하면 된다.

    • Atomicity = 성공적으로 트랜잭션은 처리하고 성공적이지 않으면 처리하지 않음.
    • Consistency = 트랜잭션이 분산 데이터를 일관된 상태에서 다른 일관된 상태로 전환해 주는지의 여부를 말함
    • Isolation = 트랜잭셩이 한꺼번에 동시에 운영되는 다른 트랜잭션과는 무관하게 실행 될 수 있는지의 여부를 의미함
    • Durability = 트랜잭션의 결과가 해당 트랜잭션이 처리된 후 남아 있는지에 관한 것을 나타냄

     

    Hive Transaction

    • HIVE는 데이터 변화를 SQL로 편하게 하는 Transaction을 0.13버전 이후에 지원하게 되었다.
    • RDB의 Transaction과 똑같은 것은 아니고 Hadoop 특성상 Insert와 Delete만 이루어지기 때문에 update와 delete를 하게 되면 그 데이터를 찾아 변경 값을 기입하고 새로운 파일로 만드는 형식으로 Transaction이 발생한다.
    • 즉, RDB의 Transaction은 직접 데이터를 찾아 수정 삭제를 하여 원본 형태를 유지하지만, HIVE Transaction은 히스토리 형식으로 변화를 기입 하여 맨마지막 기입된 것을 서칭하여 데이터를 보여주는 형식으로 동작한다.
    • Transaction을 하게 되면 파일이 많이 쌓이게 되고, 히스토리성 파일이 많이 쌓일 수록 서칭하는 범위가 늘어나 hive query 속도가 느려지게 된다. 그래서 compactor라는 속성을 이용하여 transaction이 일어났던 파일을 압축하여 하나의 파일로 유지 하는 속성을 주어 관리 해주어야 속도가 느려지지 않는다.
    • HIVE Transaction은 ACID를 지원하지만, RDB Transaction과 동일하지 않다는 것을 인식하자.

     

    Hive Transaction Component

    • Lock manager - 모든 트랜잭션 Lock관리 매니저
    • Compactor - ACID시스템을 지원하는 Metastore내에서 실행되는 일련의 백그라운드 프로세서
    • Initiator - 압축할 테이블 또는 파티션을 검색
    • Worker - Compaction 작업을 처리할 모듈
    • Cleaner - 델타 파일이 더이상 필요하지 않다고 판단하면 삭제하는 프로세스

     

    Hive 제약사항

    • Transaction을 파일로 만들어 히스토리 성으로 관리 하므로 BEGIN, COMMIT, ROLLBACK은 사용 할 수 없다. update/delete를 잘못했다면, 다시 update/delete를 해야한다.
    • ORC 파일 포맷만 지원한다.
    • external table로 만들수 없다.
    • bucket속성을 적용하여야 한다. 하지 않으면, default 속성으로 bucket 이 만들어진다.

     

    실습 해보기

    Create Transaction Table

    • Clustered 속성을 이용하여 pk를 정하는 것 처럼 컬럼 하나를 캐싱을하여 만들 수 있다.
    • Bucket을 이용하여 여러개의 파일로 나눠서 데이터를 관리 할 수 있다. transaction table은 bucket을 해야한다.
    • transaction table은 file format이 orc형식이여야한다.
    • transaction table로 만들고 싶으면 TBLPROPERTIES('transactional'='true') 을 추가하면 된다.
    hive> CREATE TABLE if not exists default.person(
        >         pid     INT,
        >         name    STRING,
        >         age     INT,
        >         address STRING
        > )
        > CLUSTERED BY (pid) into 24 BUCKETS
        > STORED AS ORC
        > LOCATION 'hdfs://namenode:8020/person/'
        > TBLPROPERTIES('transactional'='true');
    OK
    Time taken: 0.014 seconds
    

    제 도커 파일로 진행 중에 Non_ACID 오류가 난다면 아래 먼저 실행

    hive> set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
    hive> set hive.support.concurrency=true;
    


    Insert First Dummy Data

    첫번 째로 더미데이터 insert해보기

    hive> insert into table default.person values
        > (1, 'James', 22, 'Seoul'),(2, 'Tom', 23, 'New York'),(3, 'Jace', 24, 'San Francisco'),
        > (4, 'Catalina', 25, 'Virginia'),(5, 'Nilla', 31, 'Florida'),(6, 'Hyun', 32, 'Busan'),
        > (7, 'Jack', 45, 'Tokyo'),(8, 'Micheal', 82, 'Fukuoka'),(9, 'Sunny', 31, 'Gwangju'),
        > (10, 'John', 42, 'Canberra');
    WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
    Query ID = root_20221011124129_df82ba4a-de90-4f19-9f94-496e13e92271
    Total jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks determined at compile time: 24
    In order to change the average load for a reducer (in bytes):
      set hive.exec.reducers.bytes.per.reducer=<number>
    In order to limit the maximum number of reducers:
      set hive.exec.reducers.max=<number>
    In order to set a constant number of reducers:
      set mapreduce.job.reduces=<number>
    Job running in-process (local Hadoop)
    2022-10-11 12:41:30,612 Stage-1 map = 100%,  reduce = 17%
    2022-10-11 12:41:31,620 Stage-1 map = 100%,  reduce = 29%
    2022-10-11 12:41:32,624 Stage-1 map = 100%,  reduce = 79%
    2022-10-11 12:41:33,627 Stage-1 map = 100%,  reduce = 96%
    2022-10-11 12:41:34,630 Stage-1 map = 100%,  reduce = 100%
    Ended Job = job_local1575732946_0002
    Loading data to table default.person
    MapReduce Jobs Launched:
    Stage-Stage-1:  HDFS Read: 41150 HDFS Write: 505637 SUCCESS
    Total MapReduce CPU Time Spent: 0 msec
    OK
    

    첫 번째 폴더 확인

    Hadoop 파일 조회 해보면 delta라는 파일로 Transaction이 파일로 생성 된것을 볼 수 있다. 위에서 말했 듯이 Transaction Table은

    # delta 폴더가 생성 된 것을 볼 수 있다.
    hdfs dfs -ls /person/
    Found 1 items
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:41 /person/delta_0000002_0000002_0000
    
    # 24로 bucketing 했기 때문에 24개의 파일로 나눠서 적재 된 것을 볼 수 있다.
    hdfs dfs -ls /person/delta_0000002_0000002_0000
    Found 24 items
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00000
    -rw-r--r--   3 root supergroup        758 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00001
    -rw-r--r--   3 root supergroup        772 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00002
    -rw-r--r--   3 root supergroup        803 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00003
    -rw-r--r--   3 root supergroup        782 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00004
    -rw-r--r--   3 root supergroup        780 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00005
    -rw-r--r--   3 root supergroup        769 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00006
    -rw-r--r--   3 root supergroup        771 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00007
    -rw-r--r--   3 root supergroup        795 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00008
    -rw-r--r--   3 root supergroup        782 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00009
    -rw-r--r--   3 root supergroup        783 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00010
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00011
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00012
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00013
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00014
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00015
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00016
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00017
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00018
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00019
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00020
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00021
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00022
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:41 /person/delta_0000002_0000002_0000/bucket_00023
    

    Insert Second Dummy Data

    두번 째로 더미 데이터 insert해보기

    hive> insert into table default.person values
        > (11, 'James', 94, 'Seoul'),(12, 'Tom', 47, 'New York'),(13, 'Jace', 56, 'San Francisco'),
        > (14, 'Catalina', 22, 'Florida'),(15, 'Nilla', 36, 'Busan'),(16, 'Hyun', 22, 'Tokyo'),
        > (17, 'Jack', 26, 'Fukuoka'),(18, 'Micheal', 52, 'Fukuoka'),(19, 'Sunny', 38, 'Gwangju'),
        > (20, 'John', 34, 'Canberra');
    WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
    Query ID = root_20221011125206_f453e01c-8905-4081-bf9c-55f58970becc
    Total jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks determined at compile time: 24
    In order to change the average load for a reducer (in bytes):
      set hive.exec.reducers.bytes.per.reducer=<number>
    In order to limit the maximum number of reducers:
      set hive.exec.reducers.max=<number>
    In order to set a constant number of reducers:
      set mapreduce.job.reduces=<number>
    Job running in-process (local Hadoop)
    2022-10-11 12:52:07,761 Stage-1 map = 100%,  reduce = 13%
    2022-10-11 12:52:08,764 Stage-1 map = 100%,  reduce = 29%
    2022-10-11 12:52:09,767 Stage-1 map = 100%,  reduce = 46%
    2022-10-11 12:52:10,769 Stage-1 map = 100%,  reduce = 63%
    2022-10-11 12:52:12,782 Stage-1 map = 100%,  reduce = 71%
    2022-10-11 12:52:13,789 Stage-1 map = 100%,  reduce = 79%
    2022-10-11 12:52:14,795 Stage-1 map = 100%,  reduce = 88%
    2022-10-11 12:52:15,798 Stage-1 map = 100%,  reduce = 92%
    2022-10-11 12:52:16,801 Stage-1 map = 100%,  reduce = 100%
    Ended Job = job_local690935882_0003
    Loading data to table default.person
    MapReduce Jobs Launched:
    Stage-Stage-1:  HDFS Read: 77675 HDFS Write: 754962 SUCCESS
    Total MapReduce CPU Time Spent: 0 msec
    OK
    Time taken: 11.16 seconds
    

    두번 째 폴더 확인

    Transaction은 히스토리 성으로 관리 된다고 했는데 delta폴더 형식으로 관리 되는 것을 볼 수 있다.

    # 두 번째 transaction이 일너 났으므로 delta 0000003폴더가 생성된 것을 볼 수 있다.
    hdfs dfs -ls /person/
    Found 2 items
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:41 /person/delta_0000002_0000002_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:52 /person/delta_0000003_0000003_0000
    
    # 0000003폴더도 24개로 bucketing되어 데이터가 관리된것을 볼 수 있다.
    hdfs dfs -ls /person/delta_0000003_0000003_0000
    Found 24 items
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00000
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00001
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00002
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00003
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00004
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00005
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00006
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00007
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00008
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00009
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00010
    -rw-r--r--   3 root supergroup        779 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00011
    -rw-r--r--   3 root supergroup        777 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00012
    -rw-r--r--   3 root supergroup        800 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00013
    -rw-r--r--   3 root supergroup        795 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00014
    -rw-r--r--   3 root supergroup        759 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00015
    -rw-r--r--   3 root supergroup        769 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00016
    -rw-r--r--   3 root supergroup        779 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00017
    -rw-r--r--   3 root supergroup        774 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00018
    -rw-r--r--   3 root supergroup        782 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00019
    -rw-r--r--   3 root supergroup        784 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00020
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00021
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00022
    -rw-r--r--   3 root supergroup        214 2022-10-11 12:52 /person/delta_0000003_0000003_0000/bucket_00023
    

    데이터 조회

    데이터를 조회 해보면 정상적으로 나오는 것을 알 수 있다.

    hive> select * from person;
    OK
    1       James   22      Seoul
    2       Tom     23      New York
    3       Jace    24      San Francisco
    4       Catalina        25      Virginia
    5       Nilla   31      Florida
    6       Hyun    32      Busan
    7       Jack    45      Tokyo
    8       Micheal 82      Fukuoka
    9       Sunny   31      Gwangju
    10      John    42      Canberra
    11      James   94      Seoul
    12      Tom     47      New York
    13      Jace    56      San Francisco
    14      Catalina        22      Florida
    15      Nilla   36      Busan
    16      Hyun    22      Tokyo
    17      Jack    26      Fukuoka
    18      Micheal 52      Fukuoka
    19      Sunny   38      Gwangju
    20      John    34      Canberra
    Time taken: 0.126 seconds, Fetched: 20 row(s)
    

    데이터 업데이트

    # 데이터 업데이트
    hive> UPDATE person SET age = 100 WHERE pid = 20;
    WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
    Query ID = root_20221011130357_0bc1e25d-5c89-4fa7-a10d-f09301ddc4ae
    Total jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks determined at compile time: 24
    In order to change the average load for a reducer (in bytes):
      set hive.exec.reducers.bytes.per.reducer=<number>
    In order to limit the maximum number of reducers:
      set hive.exec.reducers.max=<number>
    In order to set a constant number of reducers:
      set mapreduce.job.reduces=<number>
    Job running in-process (local Hadoop)
    2022-10-11 13:03:58,446 Stage-1 map = 100%,  reduce = 8%
    2022-10-11 13:03:59,452 Stage-1 map = 100%,  reduce = 21%
    2022-10-11 13:04:00,464 Stage-1 map = 100%,  reduce = 33%
    2022-10-11 13:04:01,478 Stage-1 map = 100%,  reduce = 88%
    2022-10-11 13:04:02,484 Stage-1 map = 100%,  reduce = 100%
    Ended Job = job_local2078093802_0004
    Loading data to table default.person
    MapReduce Jobs Launched:
    Stage-Stage-1:  HDFS Read: 2302165 HDFS Write: 1802232 SUCCESS
    Total MapReduce CPU Time Spent: 0 msec
    OK
    Time taken: 5.959 seconds
    
    # update한 pid 20 조회 
    hive> select *from person where pid=20;
    OK
    20      John    100     Canberra
    Time taken: 0.215 seconds, Fetched: 1 row(s)
    

    UPDATE 한 내용 반영 되었는지 폴더 확인

    update 한것을 확인해보면 staging폴더가 생겼는데 temp폴더라고 생각하면 됩니다. 임시 저장 해 놓고 변경 된것을 적용한다음 delta 0000004 폴더에 데이터를 넣는 형식이라고 생각하면 됩니다. 아래와 같이 폴더가 staging과 delta 0000004 폴더가 생성 된 것을 확인 할 수가 있습니다.

    hdfs dfs -ls /person
    Found 4 items
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/.hive-staging_hive_2022-10-11_13-03-57_100_4202183560322431585-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:41 /person/delta_0000002_0000002_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:52 /person/delta_0000003_0000003_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/delta_0000004_0000004_0000
    

    Update를 한번 더 진행해보자

    hive>  UPDATE person SET age = 34 WHERE pid = 20;
    WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
    Query ID = root_20221011131242_a14d4f2f-ec80-4524-b5df-cad4842d2f16
    Total jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks determined at compile time: 24
    In order to change the average load for a reducer (in bytes):
      set hive.exec.reducers.bytes.per.reducer=<number>
    In order to limit the maximum number of reducers:
      set hive.exec.reducers.max=<number>
    In order to set a constant number of reducers:
      set mapreduce.job.reduces=<number>
    Job running in-process (local Hadoop)
    2022-10-11 13:12:43,239 Stage-1 map = 100%,  reduce = 8%
    2022-10-11 13:12:44,243 Stage-1 map = 100%,  reduce = 17%
    2022-10-11 13:12:45,246 Stage-1 map = 100%,  reduce = 38%
    2022-10-11 13:12:46,252 Stage-1 map = 100%,  reduce = 46%
    2022-10-11 13:12:47,255 Stage-1 map = 100%,  reduce = 58%
    2022-10-11 13:12:48,262 Stage-1 map = 100%,  reduce = 71%
    2022-10-11 13:12:49,267 Stage-1 map = 100%,  reduce = 83%
    2022-10-11 13:12:50,281 Stage-1 map = 100%,  reduce = 92%
    2022-10-11 13:12:51,288 Stage-1 map = 100%,  reduce = 100%
    Ended Job = job_local1303511095_0005
    Loading data to table default.person
    MapReduce Jobs Launched:
    Stage-Stage-1:  HDFS Read: 4784445 HDFS Write: 1889420 SUCCESS
    Total MapReduce CPU Time Spent: 0 msec
    OK
    Time taken: 9.773 seconds
    

    다시 확인해보면

    staging폴더가 생성 또 하나 생성 되고 delta 0000005파일이 생성 된것을 볼 수 있다. 이처럼 hive transaction table은 hadoop hdfs의 특성 때문에 update가 되지 않습니다. sql 형식으로 update문을 작성하는 것이지 내부적으로는 수정한 파일을 새로 만들어서 delta폴더로 히스토리 형식으로 생성 하고 select문을 날리면 delta폴더들의 내용을 종합하여 최신의 데이터만 보여주는 형식으로 진행 되게 됩니다.

    hdfs dfs -ls /person
    Found 6 items
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/.hive-staging_hive_2022-10-11_13-03-57_100_4202183560322431585-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:12 /person/.hive-staging_hive_2022-10-11_13-12-42_026_8037664498605818813-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:41 /person/delta_0000002_0000002_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:52 /person/delta_0000003_0000003_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/delta_0000004_0000004_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:12 /person/delta_0000005_0000005_0000
    

    데이터 삭제

    hive>  DELETE FROM person WHERE pid = 20;
    WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
    Query ID = root_20221011131729_63167940-1636-4b4f-9f1c-e5ac0e476621
    Total jobs = 1
    Launching Job 1 out of 1
    Number of reduce tasks determined at compile time: 24
    In order to change the average load for a reducer (in bytes):
      set hive.exec.reducers.bytes.per.reducer=<number>
    In order to limit the maximum number of reducers:
      set hive.exec.reducers.max=<number>
    In order to set a constant number of reducers:
      set mapreduce.job.reduces=<number>
    Job running in-process (local Hadoop)
    2022-10-11 13:17:30,831 Stage-1 map = 100%,  reduce = 0%
    2022-10-11 13:17:31,835 Stage-1 map = 100%,  reduce = 17%
    2022-10-11 13:17:32,839 Stage-1 map = 100%,  reduce = 38%
    2022-10-11 13:17:33,846 Stage-1 map = 100%,  reduce = 54%
    2022-10-11 13:17:34,854 Stage-1 map = 100%,  reduce = 71%
    2022-10-11 13:17:35,861 Stage-1 map = 100%,  reduce = 79%
    2022-10-11 13:17:36,864 Stage-1 map = 100%,  reduce = 100%
    Ended Job = job_local1730250867_0006
    Loading data to table default.person
    MapReduce Jobs Launched:
    Stage-Stage-1:  HDFS Read: 6058439 HDFS Write: 1974640 SUCCESS
    Total MapReduce CPU Time Spent: 0 msec
    OK
    Time taken: 7.739 seconds
    

    삭제 후 폴더 확인

    삭제도 똑같이 staging과 delta폴더가 생성된 것을 확인 할 수 있습니다.

    hdfs dfs -ls /person
    Found 8 items
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/.hive-staging_hive_2022-10-11_13-03-57_100_4202183560322431585-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:12 /person/.hive-staging_hive_2022-10-11_13-12-42_026_8037664498605818813-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:17 /person/.hive-staging_hive_2022-10-11_13-17-29_619_747000787189771293-1
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:41 /person/delta_0000002_0000002_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 12:52 /person/delta_0000003_0000003_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:04 /person/delta_0000004_0000004_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:12 /person/delta_0000005_0000005_0000
    drwxr-xr-x   - root supergroup          0 2022-10-11 13:17 /person/delta_0000006_0000006_0000
    

     

     

     

    정리하자면,

    Hive Transaction은 실제로 update, delete가 일어나는 것이 아니라 해당 내용을 수정 삭제한 새로운 파일을 만드는 작업을 합니다. 그래서 select를 하게 되면 이 폴더의 내용을 전체적으로 종합해서 최근 변화한 데이터를 보여주게 되기때문에 delta와 staging 폴더가 많아지게 되면 hql 성능이 느려지게 됩니다. 그래서 compact를 진행하여 폴더를 압축해 하나의 파일이나 폴더로 유지하는 것이 중요합니다.

     

    오늘은 Hive Transaction에 대해 알아보고 실습을 해보았습니다. 다음에는 merge 문을 실습해보고 그 다음에 compact를 진행해 보도록 하겠습니다.

     

    모든 hive sample code는 제 깃헙에 있습니다.

     

    GitHub - hyunseokjoo/hive_sample_code

    Contribute to hyunseokjoo/hive_sample_code development by creating an account on GitHub.

    github.com

     

     

     

     

     

     

     

     

    참고문헌

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML

    https://medium.com/@randy-huang/abc-b7cbaf37e4f7

    http://iarkdata.com/blog/?uid=187&mod=document

    https://118k.tistory.com/934

    반응형

    댓글

Designed by Tistory.