> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Avro, Arrow, and ORC data in ClickHouse

> Page describing how to work with Avro, Arrow and ORC data in ClickHouse

Apache has released multiple data formats actively used in analytics environments, including the popular [Avro](https://avro.apache.org/), [Arrow](https://arrow.apache.org/), and [Orc](https://orc.apache.org/). ClickHouse supports importing and exporting data using any from that list.

<h2 id="importing-and-exporting-in-avro-format">
  Importing and exporting in Avro format
</h2>

ClickHouse supports reading and writing [Apache Avro](https://avro.apache.org/) data files, which are widely used in Hadoop systems.

To import from an [avro file](https://clickhouse-docs-assets.s3.us-east-1.amazonaws.com/data.avro), we should use [Avro](/docs/reference/formats/Avro/Avro) format in the `INSERT` statement:

```sql theme={null}
INSERT INTO sometable
FROM INFILE 'data.avro'
FORMAT Avro
```

With the [file()](/docs/reference/functions/regular-functions/files#file) function, we can also explore Avro files before actually importing data:

```sql theme={null}
SELECT path, hits
FROM file('data.avro', Avro)
ORDER BY hits DESC
LIMIT 5;
```

```response theme={null}
┌─path────────────┬──hits─┐
│ Amy_Poehler     │ 62732 │
│ Adam_Goldberg   │ 42338 │
│ Aaron_Spelling  │ 25128 │
│ Absence_seizure │ 18152 │
│ Ammon_Bundy     │ 11890 │
└─────────────────┴───────┘
```

To export to Avro file:

```sql theme={null}
SELECT * FROM sometable
INTO OUTFILE 'export.avro'
FORMAT Avro;
```

<h3 id="avro-and-clickhouse-data-types">
  Avro and ClickHouse data types
</h3>

Consider [data types matching](/docs/reference/formats/Avro/Avro#data-type-mapping) when importing or exporting Avro files. Use explicit type casting to convert when loading data from Avro files:

```sql theme={null}
SELECT
    date,
    toDate(date)
FROM file('data.avro', Avro)
LIMIT 3;
```

```response theme={null}
┌──date─┬─toDate(date)─┐
│ 16556 │   2015-05-01 │
│ 16556 │   2015-05-01 │
│ 16556 │   2015-05-01 │
└───────┴──────────────┘
```

<h3 id="avro-messages-in-kafka">
  Avro messages in Kafka
</h3>

When Kafka messages use Avro format, ClickHouse can read such streams using [AvroConfluent](/docs/reference/formats/Avro/AvroConfluent) format and [Kafka](/docs/reference/engines/table-engines/integrations/kafka) engine:

```sql theme={null}
CREATE TABLE some_topic_stream
(
    field1 UInt32,
    field2 String
)
ENGINE = Kafka() SETTINGS
kafka_broker_list = 'localhost',
kafka_topic_list = 'some_topic',
kafka_group_name = 'some_group',
kafka_format = 'AvroConfluent';
```

<h2 id="working-with-arrow-format">
  Working with Arrow format
</h2>

Another columnar format is [Apache Arrow](https://arrow.apache.org/), also supported by ClickHouse for import and export. To import data from an [Arrow file](https://clickhouse-docs-assets.s3.us-east-1.amazonaws.com/data.arrow), we use the [Arrow](/docs/reference/formats/Arrow/Arrow) format:

```sql theme={null}
INSERT INTO sometable
FROM INFILE 'data.arrow'
FORMAT Arrow
```

Exporting to Arrow file works the same way:

```sql theme={null}
SELECT * FROM sometable
INTO OUTFILE 'export.arrow'
FORMAT Arrow
```

Also, check [data types matching](/docs/reference/formats/Arrow/Arrow#data-types-matching) to know if any should be converted manually.

<h3 id="arrow-data-streaming">
  Arrow data streaming
</h3>

The [ArrowStream](/docs/reference/formats/Arrow/ArrowStream) format can be used to work with Arrow streaming (used for in-memory processing). ClickHouse can read and write Arrow streams.

To demonstrate how ClickHouse can stream Arrow data, let's pipe it to the following python script (it reads input stream in Arrow streaming format and outputs the result as a Pandas table):

```python theme={null}
import sys, pyarrow as pa

with pa.ipc.open_stream(sys.stdin.buffer) as reader:
  print(reader.read_pandas())
```

Now we can stream data from ClickHouse by piping its output to the script:

```bash theme={null}
clickhouse-client -q "SELECT path, hits FROM some_data LIMIT 3 FORMAT ArrowStream" | python3 arrow.py
```

```response theme={null}
                           path  hits
0       b'Akiba_Hebrew_Academy'   241
1           b'Aegithina_tiphia'    34
2  b'1971-72_Utah_Stars_season'     1
```

ClickHouse can read Arrow streams as well using the same ArrowStream format:

```sql theme={null}
arrow-stream | clickhouse-client -q "INSERT INTO sometable FORMAT ArrowStream"
```

We've used `arrow-stream` as a possible source of Arrow streaming data.

<h2 id="importing-and-exporting-orc-data">
  Importing and exporting ORC data
</h2>

[Apache ORC](https://orc.apache.org/) format is a columnar storage format typically used for Hadoop. ClickHouse supports importing as well as exporting [Orc data](https://clickhouse-docs-assets.s3.us-east-1.amazonaws.com/data.orc) using [ORC format](/docs/reference/formats/ORC):

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

INSERT INTO sometable
FROM INFILE 'data.orc'
FORMAT ORC;
```

Also, check [data types matching](/docs/reference/formats/ORC) as well as [additional settings](/docs/reference/formats/Parquet/Parquet#format-settings) to tune export and import.

<h2 id="further-reading">
  Further reading
</h2>

ClickHouse introduces support for many formats, both text, and binary, to cover various scenarios and platforms. Explore more formats and ways to work with them in the following articles:

* [CSV and TSV formats](/docs/guides/clickhouse/data-formats/csv-tsv)
* [JSON formats](/docs/guides/clickhouse/data-formats/json/intro)
* [Regex and templates](/docs/guides/clickhouse/data-formats/templates-regex)
* [Native and binary formats](/docs/guides/clickhouse/data-formats/binary)
* [SQL formats](/docs/guides/clickhouse/data-formats/sql)

And also check [clickhouse-local](https://clickhouse.com/blog/extracting-converting-querying-local-files-with-sql-clickhouse-local) - a portable full-featured tool to work on local/remote files without the need for Clickhouse server.
