ORC 형식

ORC 형식

ORC 형식은 Hadoop 생태계에서 널리 사용되는 Apache ORC 컬럼형 저장 형식이에요. ClickHouse는 ORC 형식의 읽기와 쓰기를 지원하며, Hadoop과 데이터를 교환하려면 HDFS 테이블 엔진을 사용할 수 있습니다.

출처: 문서

본문

Input Output Alias

설명 (Description)

Apache ORC는 Hadoop 생태계에서 널리 사용되는 컬럼형 저장 형식입니다.

데이터 타입 매칭 (Data types matching)

아래 표는 지원되는 ORC 데이터 타입과 INSERT, SELECT 쿼리에서 해당 ClickHouse 데이터 타입을 비교합니다.

ORC data type ( INSERT ) ClickHouse data type ORC data type ( SELECT )
Boolean Bool Boolean
Tinyint Int8/UInt8 / Enum8 Tinyint
Smallint Int16/UInt16 / Enum16 Smallint
Int Int32/UInt32 Int
Bigint Int64/UInt64 Bigint
Float Float32 Float
Double Float64 Double
Decimal Decimal Decimal
Date Date32 Date
Timestamp DateTime64 Timestamp
String , Varchar , Binary String String
Char FixedString String
List Array List
Struct Tuple Struct
Map Map Map
Int IPv4 Int
Binary IPv6 Binary
Binary Int128/UInt128/Int256/UInt256 Binary
Binary Decimal256 Binary
Union Variant Union
  • 다른 타입은 지원되지 않습니다.
  • ORC Union 컬럼은 union의 분기 타입에 대한 Variant로 읽히고, Variant 컬럼은 분기 타입에 대한 ORC Union으로 기록됩니다. Variant는 분기 타입을 정렬하므로 분기 순서가 ORC 파일과 다를 수 있다는 점에 유의하세요. 중복 분기 타입을 가진 Union(예: uniontype<int,int>)은 지원되지 않습니다.
  • 배열은 중첩될 수 있고 인자로 Nullable 타입의 값을 가질 수 있어요. TupleMap 타입도 중첩될 수 있습니다.
  • ClickHouse 테이블 컬럼의 데이터 타입이 해당 ORC 데이터 필드와 일치할 필요는 없습니다. 데이터를 삽입할 때 ClickHouse는 위 표에 따라 데이터 타입을 해석한 다음 데이터를 ClickHouse 테이블 컬럼에 설정된 데이터 타입으로 캐스팅합니다.

사용 예시 (Example usage)

데이터 삽입 (Inserting data)

football.orc라는 이름의 ORC 파일에 다음 데이터가 있다고 가정해 볼게요:

    ┌───────date─┬─season─┬─home_team─────────────┬─away_team───────────┬─home_team_goals─┬─away_team_goals─┐
 1. │ 2022-04-30 │   2021 │ Sutton United         │ Bradford City       │               1 │               4 │
 2. │ 2022-04-30 │   2021 │ Swindon Town          │ Barrow              │               2 │               1 │
 3. │ 2022-04-30 │   2021 │ Tranmere Rovers       │ Oldham Athletic     │               2 │               0 │
 4. │ 2022-05-02 │   2021 │ Port Vale             │ Newport County      │               1 │               2 │
 5. │ 2022-05-02 │   2021 │ Salford City          │ Mansfield Town      │               2 │               2 │
 6. │ 2022-05-07 │   2021 │ Barrow                │ Northampton Town    │               1 │               3 │
 7. │ 2022-05-07 │   2021 │ Bradford City         │ Carlisle United     │               2 │               0 │
 8. │ 2022-05-07 │   2021 │ Bristol Rovers        │ Scunthorpe United   │               7 │               0 │
 9. │ 2022-05-07 │   2021 │ Exeter City           │ Port Vale           │               0 │               1 │
10. │ 2022-05-07 │   2021 │ Harrogate Town A.F.C. │ Sutton United       │               0 │               2 │
11. │ 2022-05-07 │   2021 │ Hartlepool United     │ Colchester United   │               0 │               2 │
12. │ 2022-05-07 │   2021 │ Leyton Orient         │ Tranmere Rovers     │               0 │               1 │
13. │ 2022-05-07 │   2021 │ Mansfield Town        │ Forest Green Rovers │               2 │               2 │
14. │ 2022-05-07 │   2021 │ Newport County        │ Rochdale            │               0 │               2 │
15. │ 2022-05-07 │   2021 │ Oldham Athletic       │ Crawley Town        │               3 │               3 │
16. │ 2022-05-07 │   2021 │ Stevenage Borough     │ Salford City        │               4 │               2 │
17. │ 2022-05-07 │   2021 │ Walsall               │ Swindon Town        │               0 │               3 │
    └────────────┴────────┴───────────────────────┴─────────────────────┴─────────────────┴─────────────────┘

데이터를 삽입합니다:

INSERT INTO football FROM INFILE 'football.orc' FORMAT ORC;

데이터 읽기 (Reading data)

ORC 형식을 사용하여 데이터를 읽습니다:

SELECT *
FROM football
INTO OUTFILE 'football.orc'
FORMAT ORC

ORC는 터미널에서 사람이 읽을 수 있는 형태로 표시되지 않는 바이너리 형식입니다. ORC 파일을 출력하려면 INTO OUTFILE을 사용하세요.

형식 설정 (Format settings)

Setting Description Default
output_format_orc_string_as_string String 컬럼에 Binary 대신 ORC String 타입 사용. true
output_format_orc_compression_method 출력 ORC 형식에 사용되는 압축 방법. 기본값 zstd
input_format_orc_case_insensitive_column_matching ORC 컬럼을 ClickHouse 컬럼과 매칭할 때 대소문자 무시. false
input_format_orc_allow_missing_columns ORC 데이터를 읽을 때 누락된 컬럼 허용. true
input_format_orc_skip_columns_with_unsupported_types_in_schema_inference ORC 형식의 스키마 추론 중 지원되지 않는 타입의 컬럼 건너뛰기 허용. false

Hadoop과 데이터를 교환하려면 HDFS 테이블 엔진을 사용할 수 있어요.

더 알아보기 (Learn more)