File metadata functions
Use these functions to read the metadata in the footers of Parquet files and the headers of Avro files, without reading the data.
The metadata includes schemas, row counts, column statistics, page indexes, and Bloom filters.
For a description of the sample tables and files that the examples on this page use, see Table functions in DuckDB.
avro_metadata function
Returns one row for each key-value pair in the header of an Avro object container file. The key avro.schema holds the schema of the file's records as a JSON string, and the key avro.codec, when the file has it, holds the name of the compression codec. The program that wrote the file can add other keys.
The function reads the header only. To read the records, use the read_avro function. To read parts of the schema, use JSON functions on the value column of the avro.schema row, as in the second example.
Syntax
avro_metadata(path)
Arguments
The avro_metadata function takes the following argument:
path-
The Amazon S3 path of one Avro file, as a
VARCHARvalue.
Return type
A table with the columns key (VARCHAR) and value (VARCHAR).
Examples
The following SQL query lists the header keys of an Avro file. The file is a manifest list of the Iceberg table orders_iceberg. Iceberg stores its manifest lists and manifests as Avro files.
SELECT key FROM avro_metadata( 's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/snap-1294122691170353594-d7066457-4da0-4374-822e-7f7616a4303a.avro' ) ORDER BY key
The query returns the following results.
| key |
|---|
|
|
The following SQL query reads the name of the record type and its number of fields from the schema of the same file, with JSON functions.
SELECT json_extract_string(value, '$.name') AS record_name, json_array_length(value, '$.fields') AS field_count FROM avro_metadata( 's3://amzn-s3-demo-bucket/tables/orders_iceberg/metadata/snap-1294122691170353594-d7066457-4da0-4374-822e-7f7616a4303a.avro' ) WHERE key = 'avro.schema'
The query returns the following result.
| record_name | field_count |
|---|---|
|
|
Considerations
avro_metadata reads exactly one file. It does not expand wildcards such as *, and it does not accept a list of paths. To read the metadata of several files, call it once for each file.
parquet_bloom_probe function
Returns one row for each row group of each Parquet file in path. The bloom_filter_excludes column is true when the Bloom filter of column_name in that row group shows that the row group does not contain value. It is false when the row group might contain the value, which includes a row group in which the column has no Bloom filter.
A Bloom filter can report a value that is not there, but it never misses a value that is there. A true result is therefore certain, and a false result means only that you must read the row group to know. Parquet writers often store Bloom filters for only some columns, or for none. To see which column chunks have a Bloom filter, check bloom_filter_offset in the result of parquet_metadata.
Syntax
parquet_bloom_probe(path, column_name, value)
Arguments
The parquet_bloom_probe function takes the following arguments:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]). column_name-
The name of the column to probe, as a
VARCHARvalue. value-
The value to look for. The function converts it to the type of the column, so
3and'3'both work for an integer column.
Return type
A table with one row per row group and the columns file_name (VARCHAR), row_group_id (BIGINT), and bloom_filter_excludes (BOOLEAN).
Examples
The following SQL query checks each row group of the Parquet files of sales_parquet for the customer name zed, which is not in the data. The result is false because the customer column has no Bloom filter in these files, as the second example shows.
SELECT row_group_id, bloom_filter_excludes FROM parquet_bloom_probe( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*', 'customer', 'zed' ) ORDER BY row_group_id
The query returns the following result.
| row_group_id | bloom_filter_excludes |
|---|---|
|
|
The following SQL query uses parquet_metadata to check which column chunks of the same files have a Bloom filter. For a column chunk without one, parquet_bloom_probe always returns false.
SELECT path_in_schema AS column_name, bloom_filter_offset IS NOT NULL AS has_bloom_filter FROM parquet_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' ) ORDER BY column_id
The query returns the following results.
| column_name | has_bloom_filter |
|---|---|
|
|
|
|
|
|
|
|
|
|
Considerations
The query fails if a file has no column named column_name, if value cannot be converted to the type of the column, or if column_name or value is NULL.
parquet_file_metadata function
Returns one row for each Parquet file in path, with the metadata in the file's footer. The row gives the number of rows and row groups, the name and version of the program that wrote the file (created_by), and the Parquet format version. It also gives the size of the file and of its footer in bytes, the sort order of each column's statistics, and the encryption details of an encrypted file.
For the metadata of each column chunk, use the parquet_metadata function. For the schema, use the parquet_schema function.
Syntax
parquet_file_metadata(path)
Arguments
The parquet_file_metadata function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per file. The VARCHAR columns are file_name, created_by, encryption_algorithm, and footer_signing_key_metadata. The BIGINT columns are num_rows, num_row_groups, and format_version. The UBIGINT columns are file_size_bytes and footer_size, and the column_orders column is a VARCHAR[].
Examples
The following SQL query returns the number of rows and row groups in the Parquet files of sales_parquet.
SELECT num_rows, num_row_groups FROM parquet_file_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' )
The query returns the following result.
| num_rows | num_row_groups |
|---|---|
|
|
The following SQL query passes a list of two files, the data files of the Iceberg table orders_iceberg, and adds up their rows and sizes.
SELECT count(*) AS files, sum(num_rows) AS total_rows, sum(file_size_bytes) AS total_bytes FROM parquet_file_metadata([ 's3://amzn-s3-demo-bucket/tables/orders_iceberg/data/01a20c06-c637-7eb5-bfd6-5b178259ba76.parquet', 's3://amzn-s3-demo-bucket/tables/orders_iceberg/data/01a20c06-d05e-7731-9cf5-521ecaed9e3a.parquet' ])
The query returns the following result.
| files | total_rows | total_bytes |
|---|---|---|
|
|
|
parquet_full_metadata function
Returns one row for each Parquet file in path. The row has four columns, named after the other Parquet metadata functions: parquet_file_metadata, parquet_metadata, parquet_schema, and parquet_kv_metadata. Each column is a list of STRUCT values, one for each row that the function of the same name returns for the file.
Use parquet_full_metadata to get all of a file's metadata in one call. To work with one kind of metadata, query the function for that kind, which returns the metadata as rows and columns instead of as a list of STRUCT values.
Syntax
parquet_full_metadata(path)
Arguments
The parquet_full_metadata function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per file and the columns parquet_file_metadata, parquet_metadata, parquet_schema, and parquet_kv_metadata. Each column is a list of STRUCT values whose fields are the columns that the function of the same name returns.
Examples
The following SQL query counts the column chunks and the schema elements of the Parquet file of sales_parquet, and reads its number of rows. The schema has six elements: the root and the five columns.
SELECT len(parquet_metadata) AS column_chunks, len(parquet_schema) AS schema_elements, parquet_file_metadata[1].num_rows AS num_rows FROM parquet_full_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' )
The query returns the following result.
| column_chunks | schema_elements | num_rows |
|---|---|---|
|
|
|
The following SQL query reads the data files of the Iceberg table orders_iceberg, and returns one row for each file.
SELECT parquet_file_metadata[1].num_rows AS num_rows, len(parquet_metadata) AS column_chunks FROM parquet_full_metadata( 's3://amzn-s3-demo-bucket/tables/orders_iceberg/data/*.parquet' ) ORDER BY num_rows
The query returns the following results.
| num_rows | column_chunks |
|---|---|
|
|
|
|
parquet_kv_metadata function
Returns one row for each key-value pair in the footer of each Parquet file in path. The program that writes a Parquet file can store its own metadata there, such as the schema of the data in another format. A file without key-value metadata adds no rows.
key and value are BLOB values. To read them as text, use the decode function, as in decode(key).
Syntax
parquet_kv_metadata(path)
Arguments
The parquet_kv_metadata function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per key-value pair and the columns file_name (VARCHAR), key (BLOB), and value (BLOB).
Examples
The following SQL query counts the key-value pairs in the footers of the Parquet files of sales_parquet. The count is 0 because the program that wrote these files stored no key-value metadata.
SELECT count(*) AS entries FROM parquet_kv_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' )
The query returns the following result.
| entries |
|---|
|
Considerations
decode fails on bytes that are not valid UTF-8 text. For a value that might hold binary data, use octet_length(value) to get its size, or try(decode(value)) to get NULL in place of an error.
parquet_metadata function
Returns one row for each column chunk of each row group of each Parquet file in path. A row group holds a set of rows, and a column chunk holds the values of one column in one row group. Each row gives the row group's ID and number of rows, and the column's path in the schema and its Parquet physical type. It also gives the statistics that the writer stored (stats_min_value, stats_max_value, and stats_null_count) and the compression codec and encodings. Other columns give the offsets and sizes of the column chunk in the file.
Use parquet_metadata to check the statistics, compression, and layout of a file without reading its data. For file-level metadata, use the parquet_file_metadata function.
Syntax
parquet_metadata(path)
Arguments
The parquet_metadata function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per column chunk. The VARCHAR columns are file_name, path_in_schema, type, stats_min, stats_max, stats_min_value, stats_max_value, compression, and encodings. The BIGINT columns are row_group_id, row_group_num_rows, row_group_num_columns, row_group_bytes, row_group_compressed_bytes, column_id, file_offset, num_values, stats_null_count, stats_distinct_count, stats_nan_count, index_page_offset, dictionary_page_offset, data_page_offset, total_compressed_size, total_uncompressed_size, bloom_filter_offset, bloom_filter_length, column_index_offset, column_index_length, offset_index_offset, and offset_index_length. The min_is_exact and max_is_exact columns are BOOLEAN, and the key_value_metadata column is a MAP(BLOB, BLOB). The geo_bbox column is a STRUCT of DOUBLE bounds, and the geo_types column is a VARCHAR[]. The encoding_stats column is a STRUCT(page_type VARCHAR, "encoding" VARCHAR, count INTEGER)[].
Examples
The following SQL query returns the minimum, maximum, and number of NULL values that the Parquet file of sales_parquet stores for each column.
SELECT path_in_schema AS column_name, stats_min_value AS min_value, stats_max_value AS max_value, stats_null_count AS null_count FROM parquet_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' ) ORDER BY column_id
The query returns the following results.
| column_name | min_value | max_value | null_count |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following SQL query returns the number of rows and the range of customer values in each data file of the Iceberg table orders_iceberg.
SELECT row_group_num_rows AS num_rows, stats_min_value AS min_customer, stats_max_value AS max_customer FROM parquet_metadata( 's3://amzn-s3-demo-bucket/tables/orders_iceberg/data/*.parquet' ) WHERE path_in_schema = 'customer' ORDER BY num_rows
The query returns the following results.
| num_rows | min_customer | max_customer |
|---|---|---|
|
|
|
|
|
|
Considerations
The minimum and maximum statistics (stats_min, stats_max, stats_min_value, and stats_max_value) are text (VARCHAR), whatever the type of the column. To compare one as a number or a date, cast it to that type.
row_group_id and column_id start at 0.
parquet_page_index function
Returns one row for each data page of each column chunk that has a page index, in each Parquet file in path. The page index is an optional part of a Parquet file. For each data page, it records the page's offset and compressed size, and the index of its first row and its number of rows. It also records whether the page holds only NULL values, its minimum and maximum, and its number of NULL values.
A file without a page index adds no rows. To see whether a column chunk has a page index, check column_index_offset and offset_index_offset in the result of parquet_metadata.
Syntax
parquet_page_index(path)
Arguments
The parquet_page_index function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per data page. The VARCHAR columns are file_name, path_in_schema, min_value, max_value, and boundary_order. The BIGINT columns are row_group_id, column_id, page_id, page_offset, compressed_page_size, first_row_index, num_rows, and null_count. The null_page column is a BOOLEAN.
Examples
The following SQL query counts the page index entries in the Parquet files of sales_parquet. The count is 0 because these files have no page index, as the second example shows.
SELECT count(*) AS pages FROM parquet_page_index( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' )
The query returns the following result.
| pages |
|---|
|
The following SQL query uses parquet_metadata to check which column chunks of the same files have the two parts of a page index, the column index and the offset index.
SELECT path_in_schema AS column_name, column_index_offset IS NOT NULL AS has_column_index, offset_index_offset IS NOT NULL AS has_offset_index FROM parquet_metadata( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' ) ORDER BY column_id
The query returns the following results.
| column_name | has_column_index | has_offset_index |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parquet_schema function
Returns one row for each element of the schema in the footer of each Parquet file in path. The first element of each file is the root of the schema, and the other elements are the file's columns, including the fields of nested columns. Each row gives the element's name, its Parquet physical type (type), its logical and converted types, and whether it is required, optional, or repeated (repetition_type). It also gives the element's number of children, the scale and precision of a decimal, its field ID, and the type that DuckDB reads it as (duckdb_type).
Use parquet_schema to see the columns and types of a file without reading its data, or to see the field IDs that the data files of an Iceberg table store.
Syntax
parquet_schema(path)
Arguments
The parquet_schema function takes the following argument:
path-
The Amazon S3 location of the Parquet files: a
VARCHARpath that can contain wildcards, such as*, or a list of such paths (VARCHAR[]).
Return type
A table with one row per schema element. The VARCHAR columns are file_name, name, type, type_length, repetition_type, converted_type, logical_type, and duckdb_type. The BIGINT columns are num_children, scale, precision, field_id, and column_id.
Examples
The following SQL query returns each column of the Parquet file of sales_parquet, with its Parquet physical type and the type that the engine reads it as.
SELECT name, type, duckdb_type FROM parquet_schema( 's3://amzn-s3-demo-bucket/tables/sales_parquet/*' ) WHERE type IS NOT NULL ORDER BY column_id
The query returns the following results.
| name | type | duckdb_type |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following SQL query returns the Iceberg field ID of each column in a data file of the Iceberg table orders_iceberg.
SELECT name, field_id FROM parquet_schema( 's3://amzn-s3-demo-bucket/tables/orders_iceberg/data/01a20c06-c637-7eb5-bfd6-5b178259ba76.parquet' ) WHERE field_id IS NOT NULL ORDER BY field_id
The query returns the following results.
| name | field_id |
|---|---|
|
|
|
|
|
|
|
|
|
|
Considerations
The root element has no type, so type and duckdb_type are NULL for it, and its name depends on the program that wrote the file. To list only the columns of a flat schema, filter on type IS NOT NULL.
In the result of parquet_schema, column_id is 0 for the root element, and the columns are numbered from 1. In the result of parquet_metadata, the columns are numbered from 0.