跳到主要内容
跳到主要内容

ORC

InputOutputAlias

描述

Apache ORC 是一种广泛用于 Hadoop 生态系统的列式存储格式。

数据类型匹配

下表比较了支持的 ORC 数据类型及其对应的 ClickHouse 数据类型INSERTSELECT 查询中的对应关系。

ORC 数据类型 (INSERT)ClickHouse 数据类型ORC 数据类型 (SELECT)
BooleanUInt8Boolean
TinyintInt8/UInt8/Enum8Tinyint
SmallintInt16/UInt16/Enum16Smallint
IntInt32/UInt32Int
BigintInt64/UInt32Bigint
FloatFloat32Float
DoubleFloat64Double
DecimalDecimalDecimal
DateDate32Date
TimestampDateTime64Timestamp
String, Char, Varchar, BinaryStringBinary
ListArrayList
StructTupleStruct
MapMapMap
IntIPv4Int
BinaryIPv6Binary
BinaryInt128/UInt128/Int256/UInt256Binary
BinaryDecimal256Binary
  • 其他类型不支持。
  • 数组可以嵌套,并且可以作为参数具有 Nullable 类型的值。 TupleMap 类型也可以嵌套。
  • ClickHouse 表列的数据类型不必与对应的 ORC 数据字段相匹配。在插入数据时,ClickHouse 根据上述表格解析数据类型,然后 转换 数据为设置的 ClickHouse 表列的数据类型。

示例用法

插入数据

使用以下数据的 ORC 文件,命名为 football.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;

读取数据

使用 ORC 格式读取数据:

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

ORC 是一种二进制格式,在终端上以人类可读的形式不显示。使用 INTO OUTFILE 输出 ORC 文件。

格式设置

设置描述默认值
output_format_arrow_string_as_string对于字符串列使用 Arrow String 类型而不是二进制。false
output_format_orc_compression_method输出 ORC 格式中使用的压缩方法。默认值none
input_format_arrow_case_insensitive_column_matching忽略大小写以匹配 Arrow 列与 ClickHouse 列。false
input_format_arrow_allow_missing_columns读取 Arrow 数据时允许缺少列。false
input_format_arrow_skip_columns_with_unsupported_types_in_schema_inference在 Arrow 格式的模式推断中允许跳过具有不支持类型的列。false

要与 Hadoop 交换数据,可以使用 HDFS 表引擎