title_wip

### Reading Avro data[​](#reading-avro-data "Direct link to Reading Avro data")

To read data from an Avro file into a ClickHouse table:

```
$ cat file.avro | clickhouse-client --query="INSERT INTO {some_table} FORMAT Avro"
```

The root schema of the ingested Avro file must be of type `record`.

To find the correspondence between table columns and fields of Avro schema, ClickHouse compares their names.
This comparison is case-sensitive and unused fields are skipped.

Data types of ClickHouse table columns can differ from the corresponding fields of the Avro data inserted. When inserting data, ClickHouse interprets data types according to the table above and then [casts](/docs/sql-reference/functions/type-conversion-functions#CAST) the data to the corresponding column type.

While importing data, when a field is not found in the schema and setting [`input_format_avro_allow_missing_fields`](/docs/operations/settings/formats#input_format_avro_allow_missing_fields) is enabled, the default value will be used instead of throwing an error.

### Writing Avro data[​](#writing-avro-data "Direct link to Writing Avro data")

To write data from a ClickHouse table into an Avro file:

```
$ clickhouse-client --query="SELECT * FROM {some_table} FORMAT Avro" > file.avro
```

Column names must:

- Start with `[A-Za-z_]`
- Be followed by only `[A-Za-z0-9_]`

The output compression and sync interval for Avro files can be configured using the [`output_format_avro_codec`](/docs/operations/settings/formats#output_format_avro_codec) and [`output_format_avro_sync_interval`](/docs/operations/settings/formats#output_format_avro_sync_interval) settings, respectively.

### Inferring the Avro schema[​](#inferring-the-avro-schema "Direct link to Inferring the Avro schema")

Using the ClickHouse [`DESCRIBE`](/docs/sql-reference/statements/describe-table) function, you can quickly view the inferred format of an Avro file like the following example.
This example includes the URL of a publicly accessible Avro file in the ClickHouse S3 public bucket:

```
DESCRIBE url('https://clickhouse-public-datasets.s3.eu-central-1.amazonaws.com/hits.avro','Avro);

┌─name───────────────────────┬─type────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
│ WatchID                    │ Int64           │              │                    │         │                  │                │
│ JavaEnable                 │ Int32           │              │                    │         │                  │                │
│ Title                      │ String          │              │                    │         │                  │                │
│ GoodEvent                  │ Int32           │              │                    │         │                  │                │
│ EventTime                  │ Int32           │              │                    │         │                  │                │
│ EventDate                  │ Date32          │              │                    │         │                  │                │
│ CounterID                  │ Int32           │              │                    │         │                  │                │
│ ClientIP                   │ Int32           │              │                    │         │                  │                │
│ ClientIP6                  │ FixedString(16) │              │                    │         │                  │                │
│ RegionID                   │ Int32           │              │                    │         │                  │                │
...
│ IslandID                   │ FixedString(16) │              │                    │         │                  │                │
│ RequestNum                 │ Int32           │              │                    │         │                  │                │
│ RequestTry                 │ Int32           │              │                    │         │                  │                │
└────────────────────────────┴─────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘
```

- [Description](#description)- [Data type mapping](#data-type-mapping)- [Format settings](#format-settings)- [Examples](#examples)
        - [Reading Avro data](#reading-avro-data)- [Writing Avro data](#writing-avro-data)- [Inferring the Avro schema](#inferring-the-avro-schema)

Was this page helpful?