Writing rows in Avro
To send Avro, set x-amz-payload-format to AVRO. Avro is the more efficient format for PutRows to process, especially for large payloads. If you can choose, we recommend that you use Avro.
Formatting an Avro payload
Send the rows as an Avro object container file (OCF):
-
Send exactly one Avro object container file (OCF) with at least one row. Every data block in the file must contain at least one row.
-
PutRows doesn't accept single-object encoding, the Confluent wire format, or multiple concatenated files.
-
Include the writer schema in the file header. Avro libraries do this automatically when they write an object container file.
The following example uses the fastavro library for Python to write the same two rows as the JSON example to an Avro object container file.
import datetime from fastavro import parse_schema, writer schema = parse_schema({ "type": "record", "name": "Row", "fields": [ {"name": "id", "type": "long"}, {"name": "name", "type": ["null", "string"]}, {"name": "signup", "type": {"type": "int", "logicalType": "date"}}, ], }) rows = [ {"id": 1, "name": "Alice", "signup": datetime.date(2026, 1, 15)}, {"id": 2, "name": "Bob", "signup": datetime.date(2026, 2, 3)}, ] with open("rows.avro", "wb") as f: writer(f, schema, rows)
To send the file, run the following command.
aws s3tables put-rows --table-arn $TABLE_ARN --payload-format AVRO --payload fileb://rows.avro
Mapping Avro fields to columns
PutRows matches each field in the Avro writer schema to a column in the following order:
-
If the field has a
field-idproperty, PutRows uses the column with that Iceberg field ID. -
Otherwise, PutRows matches the field's name to a column name. If the field has an
iceberg-field-nameproperty, PutRows uses that name. Otherwise, it uses the field'sname. (Not all Iceberg field names are valid Avro field names.) -
PutRows doesn't read the table's name mapping (
schema.name-mapping.default). To write a renamed column, use its current name or itsfield-id.
PutRows rejects a field that doesn't match a column. The same rules apply to fields of nested records at any depth.
To write a column's default value (its write-default in the table schema), leave the field out of the writer schema. If the column has no default, PutRows writes null to an optional column and rejects the request for a required column.
-
Every row in an Avro file has a value for every field in the writer schema, so leaving out a field applies to the whole file. To write the default in only some rows, send those rows in a separate request whose writer schema leaves out the field, or write the default value in those rows.
-
A null value doesn't write the default. PutRows writes null to an optional column and rejects null for a required column.
-
PutRows ignores a field's
defaultattribute in the writer schema.
Nullable fields
To make a field nullable, use a union of "null" and one other type, in either order, such as ["null", "string"]. PutRows doesn't accept other unions. The null branch of the union must be the string "null". e.g., ["string", {"type": "null"}] is rejected, although the Avro spec treats the object form as equivalent.
Avro data types
The following table lists the Avro types that PutRows accepts for each Iceberg column type. PutRows rejects any other Avro type.
| Iceberg type | Avro type |
|---|---|
boolean |
boolean |
int |
int |
long |
long or int |
float |
float |
double |
double or float |
decimal(P,S) |
bytes or fixed, with the decimal logical type |
date |
int, with the date logical type |
time |
long with the time-micros logical type, or int with the time-millis logical type |
timestamp, timestamp_ns |
long, with a zone-less timestamp logical type. For more information, see Timestamps in Avro. |
timestamptz, timestamptz_ns |
long, with an instant timestamp logical type. For more information, see Timestamps in Avro. |
string |
string or enum |
uuid |
fixed(16) or string, with the uuid logical type |
binary |
bytes |
fixed(L) |
fixed of size L. For a fixed(16) column, a fixed(16) with the uuid logical type is also accepted. |
geometry, geography |
bytes that contain WKB |
variant |
A record with two bytes fields, metadata and value. Both fields without logical type. |
unknown |
null, or leave out the field |
struct |
record |
list |
array |
map |
map, or an array of key-value records. For more information, see Maps in Avro. |
| Any optional column | A union with "null", such as ["null", "string"], and a null value to write a null |
| Any column with a default | Leave the field out of the writer schema, to write the default |
Note the following for specific types:
-
Logical types – Set a logical type in the writer schema, which your Avro library stores in the file header. For example, the following field is an
intwith thedatelogical type:{"name": "d", "type": {"type": "int", "logicalType": "date"}}. PutRows doesn't accept a plainintfor adatecolumn.-
PutRows rejects a logical type that it doesn't recognize (e.g. a misspelled
timestamp-milis), except on anenum, where the logical type annotation is ignored. -
PutRows doesn't accept
durationorbig-decimallogical types. -
The record for a variant may carry
"logicalType": "variant".
-
-
Numbers – PutRows doesn't accept
intorlongforfloatordoublecolumns. -
Decimals – The Avro decimal must fit the column without loss. Its scale can't be larger than the column's scale, and it can't have more integer digits than the column.
-
Times – A
timevalue must be a time of day: from 0 to 86,399,999 fortime-millis, and from 0 to 86,399,999,999 fortime-micros. -
Enums – PutRows writes an
enumas the text of its symbol, and accepts it only forstringcolumns. -
UUID strings – Use the hyphenated form, in uppercase or lowercase.
-
Variant – Send the unshredded Parquet variant encoding.
Timestamps in Avro
PutRows uses the logical type to tell an instant, which is a point in time relative to UTC, from a zone-less date and time.
| Avro logical type | Kind of value | Iceberg columns |
|---|---|---|
timestamp-millis, timestamp-micros, timestamp-nanos |
Instant | timestamptz, timestamptz_ns |
timestamp-millis, timestamp-micros, timestamp-nanos with "adjust-to-utc": false |
Zone-less | timestamp, timestamp_ns |
local-timestamp-millis, local-timestamp-micros, local-timestamp-nanos |
Zone-less | timestamp, timestamp_ns |
-
PutRows doesn't accept an instant for a zone-less column, or a zone-less value for a column with a time zone.
-
PutRows converts milliseconds and microseconds to the column's unit.
-
PutRows doesn't accept nanosecond values for microsecond columns, because the conversion would lose precision.
-
Microsecond columns hold dates about 292,000 years before and after 1970. PutRows rejects a millisecond value outside that range.
-
Nanosecond columns hold dates from 1677-09-21 to 2262-04-11. PutRows rejects a value outside that range.
Maps in Avro
-
For maps with
stringkeys, use an Avromap. -
For any key type, you can use an
arraywith"logicalType": "map". Each item is a record with two fields: the first is the key, and the second is the value. -
Map keys can't be nullable.
-
As in JSON, PutRows doesn't support
geometry,geography, orvariantas map key types. -
PutRows rejects duplicate keys. Keys are compared by value, as in JSON.