Skip to main content

Export: Avro

Converts the data contract into an Avro schema. It supports specifying custom Avro properties for logical types and default values.

datacontract export avro orders.odcs.yaml --schema-name orders --output orders.avsc

Running this against the example orders contract produces:

{
"type": "record",
"name": "orders",
"doc": "One row per customer order.",
"fields": [
{
"name": "order_id",
"doc": "Unique identifier of the order.",
"type": "string"
},
{
"name": "order_timestamp",
"doc": "Timestamp when the order was placed.",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "customer_id",
"doc": "Reference to the customer who placed the order.",
"type": "string"
},
{
"name": "order_total",
"doc": "Total amount of the order in cents.",
"type": "int"
},
{
"name": "status",
"doc": "Current fulfilment status of the order.",
"type": "string"
}
]
}

Custom Avro properties​

customProperties may set additional Avro attributes. At the moment, logicalType, default and aliases are supported.

schema:
- name: orders
properties:
- name: my_field_1
description: Example for AVRO with Timestamp (microsecond precision)
logicalType: integer
physicalType: long
examples:
- 1672534861000000 # 2023-01-01 01:01:01 in microseconds
required: true
customProperties:
- property: avroLogicalType
value: local-timestamp-micros
- property: avroDefault
value: "1672534861000000"
  • avroLogicalType — the Avro logical type of the property (here local-timestamp-micros).
  • avroDefault — the default value for the property in Avro, as a string; true, false, null and numbers are converted to their Avro type.
  • avroAliases — the field's alternate names, as a list. On the schema object, it sets the aliases of the top-level record.

All options: datacontract export avro.