Table formats, file formats, and SerDes in DuckDB
With DuckDB, you can read and write Hive tables and Apache Iceberg tables in the AWS Glue Data Catalog, and you can read data files directly from Amazon S3. Whether DuckDB can read a table depends on the table format, the SerDe (serializer and deserializer) that the table uses, and how the files are compressed.
The examples in this topic use a database named sales_db and files under s3://amzn-s3-demo-bucket/. To run the examples, replace these names with your own database and Amazon S3 location. Athena engine version 3 created most of the tables with CTAS queries. The tables hold orders from the same small set, and the amount column holds the order total in US dollars (USD).
Supported SerDes and file formats
The following table lists the SerDes that tables in the AWS Glue Data Catalog can use, and whether DuckDB reads and writes them. Write means CREATE TABLE, CTAS, and INSERT INTO.
| Data format | Read | Write | SerDe |
|---|---|---|---|
Apache Parquet |
Yes |
Yes |
|
Apache Avro |
Yes |
Yes |
|
CSV, TSV, and other delimited text |
Yes |
Yes |
|
CSV with quoted fields |
Yes |
Yes |
|
JSON |
Yes |
Yes |
|
JSON |
Yes |
No |
|
Apache ORC |
No |
No |
|
Amazon Ion |
No |
No |
|
Regex |
No |
No |
|
Grok |
No |
No |
|
RCFile |
No |
No |
|
CloudTrail logs |
No |
No |
|
Hadoop SequenceFile |
No |
No |
|
The SerDe column gives the last part of the class name in the table's SerDe serialization library. For example, ParquetHiveSerDe stands for org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe.
When a query reads a table whose SerDe DuckDB doesn't support, the query fails with an error that names the SerDe. A query of a CloudTrail table fails with an error that says that CloudTrail log tables aren't supported. For more information about these SerDes in Athena engine version 3, see Choose a SerDe for your data.
Tables stored as SequenceFile are the exception. DuckDB reads their files as plain text, so a query of such a table doesn't fail but returns wrong values. INSERT INTO such a table fails.
For more information about the properties of each SerDe that DuckDB reads, see Delimited text (LazySimpleSerDe), Quoted CSV (OpenCSVSerde), and JSON.
The following SQL query reads an ORC table.
SELECT * FROM sales_db.orders_orc
The query fails with an error that says that tables with the ORC SerDe aren't supported.
The following SQL query reads the Parquet table that Athena engine version 3 wrote. Amounts are in US dollars (USD).
SELECT order_id, customer, amount, notes FROM sales_db.orders_parquet ORDER BY order_id
The query returns the following results.
| order_id | customer | amount | notes |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table formats
With DuckDB, you can use the following table formats in the AWS Glue Data Catalog:
Hive tables, partitioned or not, in the file formats that Supported SerDes and file formats marks as readable. DuckDB reads bucketed Hive tables, but it can't create them, and
INSERT INTOa bucketed table fails.Apache Iceberg tables with Parquet data files. The Iceberg tables that DuckDB creates use Parquet data files. A query of an Iceberg table whose data files are ORC or Avro fails with an error that says that the file format isn't supported.
DuckDB doesn't read or write the following tables. A query of one of them fails with an error that names the table format:
Delta Lake tables
Apache Hudi tables
Tables that use
SymlinkTextInputFormatto list their data files in manifest filesTables that use partition projection (
projection.enabledset totrue)
To read a table that uses partition projection with DuckDB, register its partitions in the AWS Glue Data Catalog and set projection.enabled to false. This change also applies to Athena engine version 3, which then reads only the partitions registered in the AWS Glue Data Catalog. For more information about partition projection, see Use partition projection with Amazon Athena.
The following SQL query reads a Hive table that is partitioned by region.
SELECT region, count(*) AS orders FROM sales_db.orders_by_region GROUP BY region ORDER BY region
The query returns the following results.
| region | orders |
|---|---|
|
|
|
|
|
|
The following SQL query reads a table that the AWS Glue Data Catalog marks as a Delta Lake table.
SELECT * FROM sales_db.orders_delta
The query fails with an error that says that Delta Lake tables aren't supported.
The following SQL query reads an Iceberg table that Athena engine version 3 created with ORC data files.
SELECT * FROM sales_db.orders_iceberg_orc
The query fails with an error that says that the file format isn't supported. To read the data, use Athena engine version 3 to copy it into an Iceberg table with Parquet data files, for example with a CTAS query.
Compression
The following table lists the compression codecs that DuckDB reads and writes for each file format.
| File format | Reads | Writes |
|---|---|---|
Parquet |
Snappy, GZIP, ZSTD, Brotli, LZ4_RAW, and uncompressed files |
Snappy (the default), GZIP, and ZSTD |
Avro |
Snappy, Deflate, bzip2, ZSTD, and uncompressed files |
Uncompressed (the default), Snappy, Deflate, bzip2, and ZSTD |
CSV, other delimited text, and JSON |
gzip ( |
Uncompressed (the default), gzip, and Zstandard |
Parquet and Avro files record their codec, so DuckDB reads them whatever their file names are. For text and JSON files, DuckDB goes by the file name extension. It decompresses files whose names end in .gz or .zst. It can't read files whose names end in .bz2 (bzip2) or .lz4 (LZ4), and the query fails with an error that names the compression type. It reads every other file as uncompressed text.
DuckDB can't read text and JSON files compressed with Snappy (.snappy). Because it reads them as uncompressed text, the query fails with an error that says that the file isn't valid UTF-8 or isn't valid JSON.
The following SQL query reads a CSV table whose files Athena engine version 3 compressed with bzip2.
SELECT * FROM sales_db.orders_text_bzip2
The query fails with an error that says that the bzip2 compression type isn't supported.
To choose the codec of the files that DuckDB writes, set write_compression when you create the table. The value is not case-sensitive. When you insert rows into a Parquet, text, or JSON table that Athena engine version 3 created, DuckDB uses the compression that the table records. If the table records a codec that DuckDB can't write, such as bzip2 for text, the INSERT statement fails. For more information about compression in Athena engine version 3, see Use compression in Athena.
The following SQL statement creates a JSON table whose files are compressed with gzip. Amounts are in US dollars (USD).
CREATE TABLE sales_db.orders_gzip ( order_id INTEGER, customer VARCHAR, amount DECIMAL(10,2) ) WITH ( type = 'HIVE', format = 'json', write_compression = 'gzip', location = 's3://amzn-s3-demo-bucket/tables/gzip/' )
The statement returns no rows.
The following SQL statement adds two orders to the table. Amounts are in US dollars (USD).
INSERT INTO sales_db.orders_gzip VALUES (1, 'Jane Doe', 120.50), (2, 'Carlos Salazar', 75.00)
The statement returns no rows.
The following SQL query lists the files of the table and checks their names.
SELECT count(*) AS files, bool_and(file LIKE '%.json.gz') AS all_gzip FROM glob('s3://amzn-s3-demo-bucket/tables/gzip/*')
The query returns the following result.
| files | all_gzip |
|---|---|
|
|
Delimited text (LazySimpleSerDe)
Tables that use org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe hold one row per line, with fields separated by a delimiter. DuckDB creates this kind of table when you set format = 'csv' without a quote or escape property. The SerDe doesn't treat quotation marks as special, so a quoted field keeps its quotation marks.
The following table shows how DuckDB handles the SerDe properties and table properties of these tables.
| Property | How DuckDB handles it |
|---|---|
|
Sets the field delimiter. Tables that you create with |
|
Sets the text that stands for |
|
Sets the escape character. Reads remove it, and writes add it before each delimiter in a value. To set it in |
|
Skips that many lines at the start of each file. When the value is |
|
Sets the patterns that DuckDB parses |
|
Not supported. Queries of the table fail. |
|
Only UTF-8 is supported. Queries of a table with another encoding fail. |
A field that doesn't fit the column type reads as NULL. Columns of type ARRAY, MAP, or STRUCT aren't supported, and a query of a table that has one fails.
The following SQL query reads a table whose files use a vertical bar as the delimiter, NA as the NULL text, and one header line. Amounts are in US dollars (USD).
SELECT * FROM sales_db.orders_pipe ORDER BY order_id
The query returns the following results.
| order_id | customer | amount | notes |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
When a value that you insert holds the field delimiter or a line break, or equals the NULL text, the whole INSERT statement fails. If the table has an escape character, DuckDB escapes the delimiter, so the table can store values that hold it. A quoted CSV table can also store values that hold the delimiter. To store values that hold line breaks, use a Parquet table.
The following SQL statement creates a CSV table.
CREATE TABLE sales_db.orders_csv ( order_id INTEGER, customer VARCHAR, notes VARCHAR ) WITH ( type = 'HIVE', format = 'csv', location = 's3://amzn-s3-demo-bucket/tables/orders_csv/' )
The statement returns no rows.
The following SQL statement inserts a value that holds a comma.
INSERT INTO sales_db.orders_csv VALUES (1, 'Jane Doe', 'gift wrap, fragile')
The statement fails with an error that says that a value holds the field delimiter or a line break, or is the NULL text.
Quoted CSV (OpenCSVSerde)
Tables that use org.apache.hadoop.hive.serde2.OpenCSVSerde can hold fields in quotation marks, so a value can hold the delimiter. DuckDB creates this kind of table when you set format = 'csv' and a quote or escape property. When it writes the table, it puts every value in quotation marks, and it writes NULL as an empty field without quotation marks. A value that holds a line break makes the INSERT statement fail.
Keep the following in mind for these tables:
The SerDe properties
separatorChar,quoteChar, andescapeCharset the delimiter, the quotation character, and the escape character. The defaults are a comma, a double quotation mark, and the quotation character. WhenescapeCharisn't set, DuckDB also treats a backslash as an escape character, soC:\tempreads asC:temp.The SerDe has no
NULLvalue. An empty field reads as an empty string.A field that doesn't fit the column type makes the query fail, and so does an empty field in a column that isn't a string. To read such fields as
NULL, set the table propertyuse.null.for.invalid.datatotrue.When you insert
NULLinto a column that isn't a string, DuckDB writes an empty field. Later queries that read that column fail unless the table setsuse.null.for.invalid.datatotrue.A
BOOLEANfield reads astruewhen it holdstruein any letter case. Any other value reads asfalse, even withuse.null.for.invalid.data.A
TIMESTAMPfield holds milliseconds since 1970-01-01 00:00:00 UTC, and aDATEfield holds days since 1970-01-01. DuckDB writes these columns the same way.
The following SQL query reads the rows with notes from a table whose file has quoted fields and a header line. Amounts are in US dollars (USD).
SELECT order_id, customer, amount, notes FROM sales_db.orders_opencsv WHERE notes <> '' ORDER BY order_id
The query returns the following results.
| order_id | customer | amount | notes |
|---|---|---|---|
|
|
|
|
|
|
|
|
The following SQL statement creates a CSV table with quoted fields.
CREATE TABLE sales_db.orders_quoted ( order_id INTEGER, customer VARCHAR, notes VARCHAR ) WITH ( type = 'HIVE', format = 'csv', quote = '"', location = 's3://amzn-s3-demo-bucket/tables/quoted/' )
The statement returns no rows.
The following SQL statement inserts a value that holds a comma, and a NULL value.
INSERT INTO sales_db.orders_quoted VALUES (1, 'Jane Doe', 'gift wrap, fragile'), (2, 'Carlos Salazar', NULL)
The statement returns no rows.
The following SQL query reads the rows back. It shows the length of each value, which includes the comma, and checks whether the NULL value came back as NULL or as an empty string.
SELECT order_id, length(notes) AS notes_length, notes IS NULL AS notes_is_null, notes = '' AS notes_is_empty FROM sales_db.orders_quoted ORDER BY order_id
The query returns the following results.
| order_id | notes_length | notes_is_null | notes_is_empty |
|---|---|---|---|
|
|
|
|
|
|
|
|
JSON
DuckDB reads tables that use the Hive JSON SerDe (org.apache.hive.hcatalog.data.JsonSerDe) or the OpenX JSON SerDe (org.openx.data.jsonserde.JsonSerDe). Each line of a file must hold one JSON object. A JSON object that spans several lines makes the query fail. Keys match column names whatever their case. Columns of type ARRAY, MAP, and STRUCT are supported.
When you create a JSON table, DuckDB uses the Hive JSON SerDe. It can't insert rows into a table that uses the OpenX JSON SerDe.
The following table shows how DuckDB handles the SerDe properties of the OpenX JSON SerDe.
| Property | How DuckDB handles it |
|---|---|
|
With |
|
With |
|
With |
|
DuckDB ignores it and reads each column from the key with the column's own name. |
|
DuckDB ignores it. For example, a |
Keep the following in mind when you read JSON tables with either SerDe:
A number with a fractional part reads into an integer column rounded to the nearest whole number, not truncated. A value exactly halfway between two whole numbers rounds to the even one. For example,
0.54reads as1,2.5reads as2,3.5reads as4, and-1.7reads as-2.In a
BOOLEANcolumn, the number1and the string"yes"read astrue.A string that holds a whole number, such as
"51", reads into anINTcolumn as that number.A
TIMESTAMPvalue must be text, such as2026-10-01 12:34:56.789. A number, such as seconds or milliseconds since 1970-01-01, makes the query fail. DuckDB ignores thetimestamp.formatsSerDe property of the Hive JSON SerDe, so a value such as10/01/2026 12:34makes the query fail even whentimestamp.formatsmatches it.When a
TIMESTAMPvalue has a time zone offset, DuckDB drops the offset. For example,2026-10-01 12:34:00+02:00reads as2026-10-01 12:34:00.A JSON object in a string column reads as its JSON text, such as
{"k":1}.A key that appears twice in one object makes the query fail. With the OpenX JSON SerDe and
ignore.malformed.jsonset totrue, the column gets the first of the two values.Two JSON objects on one line make the query fail. With the OpenX JSON SerDe and
ignore.malformed.jsonset totrue, the line reads as a row ofNULLvalues, so neither object is read.DuckDB skips empty lines.
The following SQL query reads a table that sets ignore.malformed.json to true and maps the ship_city column to the key ship.city. One line of the file isn't JSON.
SELECT * FROM sales_db.orders_openx ORDER BY order_id
The query returns the following results.
| order_id | customer | ship_city |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
The line that isn't JSON comes back as a row of NULL values. The ship_city column is NULL in every row, because DuckDB doesn't apply the mapping.
The following SQL query reads the JSON table that Athena engine version 3 wrote with the Hive JSON SerDe. Amounts are in US dollars (USD).
SELECT order_id, customer, amount, order_date FROM sales_db.orders_json ORDER BY order_id
The query returns the following results.
| order_id | customer | amount | order_date |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Avro
DuckDB reads each Avro file with the schema stored in the file. It matches the file's fields to the table columns by name, so the column order can differ.
The following SQL query reads the Avro table that Athena engine version 3 wrote. Amounts are in US dollars (USD).
SELECT order_id, customer, amount, shipped_at FROM sales_db.orders_avro ORDER BY order_id
The query returns the following results.
| order_id | customer | amount | shipped_at |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read data in formats that DuckDB doesn't support
For ORC and Ion tables, use Athena engine version 3 to rewrite the data in Parquet with a CTAS query, and then query the new table. For tables of text logs, you can often read the files directly with the functions that read files, as the following examples show.
CloudTrail log files hold one JSON object per file, with the events in its Records array. The following SQL query reads the events with the read_json function and turns each one into a row with the unnest function.
SELECT r.eventTime AS event_time, r.eventName AS event_name, r.userIdentity.userName AS user_name FROM ( SELECT unnest(Records) AS r FROM read_json( 's3://amzn-s3-demo-bucket/cloudtrail/**/*.json.gz' ) ) ORDER BY event_time
The query returns the following results.
| event_time | event_name | user_name |
|---|---|---|
|
|
|
|
|
|
A table that uses the Regex SerDe describes the fields of a log line with a regular expression. The following SQL query reads the lines of a web server log with the read_text function and splits them into fields with the regexp_extract function.
WITH lines AS ( SELECT unnest(string_split(content, chr(10))) AS line FROM read_text( 's3://amzn-s3-demo-bucket/logs/access.log' ) ), fields AS ( SELECT regexp_extract( line, '^(\S+) .*"(\S+) (\S+) [^"]*" (\d+)', ['client', 'method', 'path', 'status'] ) AS r FROM lines WHERE line <> '' ) SELECT r.client, r.method, r.path, r.status FROM fields ORDER BY r.client
The query returns the following results.
| client | method | path | status |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Read files directly from Amazon S3
To read files without a table, call a function that reads files with an s3:// path, or name a file path in the FROM clause. These functions include the read_parquet function, the read_csv function, the read_json function, and the read_avro function.
These functions accept paths with wildcards such as *. These reads use the IAM permissions of the principal that runs the query, and they don't use table definitions from the AWS Glue Data Catalog.
The following SQL query reads the gzip-compressed CSV files of a Hive table directly.
SELECT order_id, customer, shipped_at, notes FROM read_csv( 's3://amzn-s3-demo-bucket/tables/orders_text/*', header = false, columns = { 'order_id': 'INTEGER', 'customer': 'VARCHAR', 'region': 'VARCHAR', 'amount': 'DECIMAL(10,2)', 'order_date': 'DATE', 'shipped_at': 'TIMESTAMP', 'notes': 'VARCHAR' }, nullstr = '\N' ) ORDER BY order_id
The query returns the following results.
| order_id | customer | shipped_at | notes |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The header option says that the files have no header line. The columns option names each field of the files in order, with its type. The nullstr option names the text that the table uses for NULL.
The following SQL query names a Parquet file in the FROM clause. Amounts are in US dollars (USD).
SELECT * FROM 's3://amzn-s3-demo-bucket/data/orders.parquet' ORDER BY order_id
The query returns the following results.
| order_id | customer | amount |
|---|---|---|
|
|
|
|
|
|
|
|
|
If you name a file that doesn't exist, the error says that the Amazon S3 bucket doesn't exist, even when the bucket exists. If a path with wildcards matches no files, the error says that no files match the pattern. Error messages don't include the path, so check the path in the query when you get either error.
The following SQL query reads a file that doesn't exist.
SELECT count(*) AS orders FROM read_parquet( 's3://amzn-s3-demo-bucket/data/missing.parquet' )
The query fails with an error that says that the specified Amazon S3 bucket doesn't exist.
Choose the format of a new table
In a CREATE TABLE statement, the format property sets the file format of a Hive table: 'parquet' (the default), 'csv', 'json', or 'avro'. Other values, such as 'orc', 'textfile', and 'ion', make the statement fail.
Some properties that Athena engine version 3 CTAS queries use have other names in DuckDB, or no equivalent. The following table lists them.
| Athena engine version 3 property | DuckDB equivalent |
|---|---|
|
|
|
A |
|
|
|
|
|
No equivalent. DuckDB can't create bucketed tables, and the statement fails. |
The defaults of format = 'csv' differ from TEXTFILE in Athena engine version 3. DuckDB uses a comma and no compression, and Athena engine version 3 uses \001 and GZIP.
Most other properties that DuckDB doesn't know become table properties in the AWS Glue Data Catalog, without an error. For example, compression = 'zstd' doesn't change the codec, but write_compression = 'zstd' does. For more information about the other properties of new tables, see CREATE TABLE and CREATE TABLE AS statements in DuckDB.
Differences from Athena engine version 3
Keep the following differences in mind when you query the same tables with Athena engine version 3 and DuckDB:
DuckDB doesn't read ORC, Ion, Regex, Grok, RCFile, or CloudTrail tables, Delta Lake or Hudi tables, symlink tables, or tables that use partition projection.
DuckDB doesn't read Iceberg tables whose data files are ORC or Avro.
DuckDB doesn't support tables stored as SequenceFile.
DuckDB can't read delimited text tables with
ARRAY,MAP, orSTRUCTcolumns, which Athena engine version 3 can create.DuckDB doesn't read text or JSON files compressed with bzip2, LZ4, or Snappy.
DuckDB doesn't apply the
mapping.*anddots.in.keysproperties of the OpenX JSON SerDe, or thetimestamp.formatsproperty of the Hive JSON SerDe.In JSON tables, a number with a fractional part reads into an integer column rounded on DuckDB and truncated toward zero on Athena engine version 3. For example,
0.54reads as1on DuckDB and as0on Athena engine version 3, and1.5reads as2and as1.In Hive JSON tables, a string that holds a whole number, such as
"51", reads into anINTcolumn on DuckDB. On Athena engine version 3, the query fails.In JSON tables, the number
1and the string"yes"read astruein aBOOLEANcolumn on DuckDB, and asfalseon Athena engine version 3.In OpenX JSON tables, Athena engine version 3 reads a number in a
TIMESTAMPcolumn as seconds or milliseconds since 1970-01-01. On DuckDB, the query fails.In JSON tables, DuckDB reads a
TIMESTAMPvalue with a time zone offset, such as+02:00, and drops the offset. On Athena engine version 3, the query fails.In JSON tables, a key that appears twice in one object, or two JSON objects on one line, make the query fail on DuckDB. Athena engine version 3 uses the last of the two values, and reads only the first object on the line. In OpenX JSON tables with
ignore.malformed.jsonset totrue, DuckDB uses the first of the two values, and reads a line with two objects as a row ofNULLvalues.DuckDB writes Parquet with Snappy by default, and text and JSON uncompressed by default. Athena engine version 3 uses GZIP for these formats by default.
DuckDB can't create bucketed tables. Athena engine version 3 creates them with the
bucketed_byandbucket_countCTAS properties.