> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Документация по формату ORC

# ORC

| Ввод | Вывод | Псевдоним |
| - | - | - |
| ✔ | ✔ | |

<div id="description">
  ## Описание
</div>

[Apache ORC](https://orc.apache.org/) — это столбцовый формат хранения данных, широко используемый в экосистеме [Hadoop](https://hadoop.apache.org/).

<div id="data-types-matching-orc">
  ## Сопоставление типов данных
</div>

В таблице ниже приведено сравнение поддерживаемых типов данных ORC и соответствующих им [типов данных](/ru/reference/data-types/index) ClickHouse в запросах `INSERT` и `SELECT`.

| Тип данных ORC (`INSERT`) | Тип данных ClickHouse | Тип данных ORC (`SELECT`) |
| - | - | - |
| `Boolean` | [Bool](/ru/reference/data-types/boolean) | `Boolean` |
| `Tinyint` | [Int8/UInt8](/ru/reference/data-types/int-uint)/[Enum8](/ru/reference/data-types/enum) | `Tinyint` |
| `Smallint` | [Int16/UInt16](/ru/reference/data-types/int-uint)/[Enum16](/ru/reference/data-types/enum) | `Smallint` |
| `Int` | [Int32/UInt32](/ru/reference/data-types/int-uint) | `Int` |
| `Bigint` | [Int64/UInt64](/ru/reference/data-types/int-uint) | `Bigint` |
| `Float` | [Float32](/ru/reference/data-types/float) | `Float` |
| `Double` | [Float64](/ru/reference/data-types/float) | `Double` |
| `Decimal` | [Decimal](/ru/reference/data-types/decimal) | `Decimal` |
| `Date` | [Date32](/ru/reference/data-types/date32) | `Date` |
| `Timestamp` | [DateTime64](/ru/reference/data-types/datetime64) | `Timestamp` |
| `String`, `Varchar`, `Binary` | [String](/ru/reference/data-types/string) | `String` |
| `Char` | [FixedString](/ru/reference/data-types/fixedstring) | `String` |
| `List` | [Array](/ru/reference/data-types/array) | `List` |
| `Struct` | [Tuple](/ru/reference/data-types/tuple) | `Struct` |
| `Map` | [Map](/ru/reference/data-types/map) | `Map` |
| `Int` | [IPv4](/ru/reference/data-types/int-uint) | `Int` |
| `Binary` | [IPv6](/ru/reference/data-types/ipv6) | `Binary` |
| `Binary` | [Int128/UInt128/Int256/UInt256](/ru/reference/data-types/int-uint) | `Binary` |
| `Binary` | [Decimal256](/ru/reference/data-types/decimal) | `Binary` |
| `Union` | [Variant](/ru/reference/data-types/variant) | `Union` |

* Другие типы не поддерживаются.
* Столбец ORC `Union` считывается как [Variant](/ru/reference/data-types/variant) с типами ветвей объединения, а столбец `Variant` записывается как ORC `Union` с его типами ветвей. Обратите внимание, что `Variant` сортирует типы ветвей, поэтому порядок ветвей может отличаться от порядка в ORC-файле. Объединения с повторяющимися типами ветвей (например, `uniontype<int,int>`) не поддерживаются.
* Массивы могут быть вложенными и принимать в качестве аргумента значение типа `Nullable`. Типы `Tuple` и `Map` также могут быть вложенными.
* Типы данных столбцов таблицы ClickHouse не обязаны совпадать с соответствующими полями данных ORC. При вставке данных ClickHouse интерпретирует типы данных в соответствии с таблицей выше, а затем [преобразует](/ru/reference/functions/regular-functions/type-conversion-functions#CAST) данные к типу, заданному для столбца таблицы ClickHouse.

<div id="example-usage">
  ## Пример использования
</div>

<div id="inserting-data">
  ### Вставка данных
</div>

Используя ORC-файл со следующими данными, названный `football.orc`:

```text theme={null}
    ┌───────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 │
    └────────────┴────────┴───────────────────────┴─────────────────────┴─────────────────┴─────────────────┘
```

Вставьте данные:

```sql theme={null}
INSERT INTO football FROM INFILE 'football.orc' FORMAT ORC;
```

<div id="reading-data">
  ### Чтение данных
</div>

Для чтения данных используйте формат `ORC`:

```sql theme={null}
SELECT *
FROM football
INTO OUTFILE 'football.orc'
FORMAT ORC
```

<Tip>
  ORC — это бинарный формат, который не отображается в терминале в удобочитаемом для человека виде. Используйте `INTO OUTFILE` для вывода файлов ORC.
</Tip>

<div id="format-settings">
  ## Настройки формата
</div>

| Настройка | Описание | По умолчанию |
| - | - | - |
| [`output_format_orc_string_as_string`](/ru/reference/settings/formats/output-format#output_format_orc_string_as_string) | Использовать тип ORC String вместо Binary для столбцов String. | `true` |
| [`output_format_orc_compression_method`](/ru/reference/settings/formats/output-format#output_format_orc_compression_method) | Метод сжатия, используемый для выходного формата ORC. Значение по умолчанию | `zstd` |
| [`input_format_orc_case_insensitive_column_matching`](/ru/reference/settings/formats/input-format#input_format_orc_case_insensitive_column_matching) | Игнорировать регистр при сопоставлении столбцов ORC со столбцами ClickHouse. | `false` |
| [`input_format_orc_allow_missing_columns`](/ru/reference/settings/formats/input-format#input_format_orc_allow_missing_columns) | Разрешить отсутствующие столбцы при чтении данных ORC. | `true` |
| [`input_format_orc_skip_columns_with_unsupported_types_in_schema_inference`](/ru/reference/settings/formats/input-format#input_format_orc_skip_columns_with_unsupported_types_in_schema_inference) | Разрешить пропускать столбцы с неподдерживаемыми типами при автоматическом определении схемы для формата ORC. | `false` |

Для обмена данными с Hadoop можно использовать [движок таблицы HDFS](/ru/reference/engines/table-engines/integrations/hdfs).
