Step 1. Export data to Avro
Please refer to the documentation of your database for instructions on exporting data to Avro. You will need to export one file per table, with the following requirements:- Files must be self-contained object container file (OFC) or a binary or JSON file containing one Avro record per line.
- Files must be UTF-8 encoded.
Data type mapping
Avro data types will be flexibly mapped to the target schema; that is, Avro and CockroachDB SQL types do not need to match exactly. By default, CockroachDB ignores unknown Avro fields and sets any columns toNULL if they were not set in the Avro record.
Use the table below for data type mappings:
| Avro Data Type | CockroachDB Data Type |
|---|---|
BOOL | , |
INT | , |
FLOAT | , |
STRING | |
BYTES | , |
ARRAY | , |
UUID | |
DATE | |
TIME | |
INTERVAL | |
TIMESTAMP | |
JSON | |
BIT | |
DECIMAL |
CockroachDB will attempt to convert the Avro data type to the CockroachDB data type; otherwise, it will report an error.
Step 2. Host the files where the cluster can access them
Each node in the CockroachDB cluster needs to have access to the files being imported. There are several ways for the cluster to access the data; for more information on the types of storage can pull from, see the following:Step 3. Import the Avro
To import Avro data:Import an object container file
An object container file (OCF) is a self-contained Avro file and includes both the table schema and records. For Avro OCF, thestrict_validation import option rejects Avro records that do not have a one-to-one data type mapping to the target schema. By default, CockroachDB ignores unknown Avro fields and sets missing SQL fields to NULL.
The following example uses sample data from Teradata.
userdata1.avro into an employees table, issue the following statement:
IMPORT INTO to import the data into the new table:
You will need to run to add any foreign key relationships.
Import binary or JSON records
In addition to importing Avro OCF, you can also import a binary or JSON file containing Avro records:- To import a binary file, use the
data_as_binary_recordsoption. - To import a JSON file, use the
data_as_json_recordsoption.
- Specify the schema inline with the
schemaoption. - Specify the schema by pointing to the file with the
schema_urioption.
strict_validation, which rejects Avro records that do not have a one-to-one data type mapping to the target schema. By default, CockroachDB ignores unknown Avro fields and sets missing SQL fields toNULL.records_terminated_by, which specifies the unicode character used to indicate new lines in the input binary or JSON file (default:\n).
The following example uses sample data generated by Avro tools.
simple-schema.json into a simple table, first to import into. Then run IMPORT INTO with the following options:

