READ_AVRO returns a table with data from the specified Avro file and supports all Avro data types.
READ_AVRO supports only binary encoded Avro files (typically with the .avro extension). JSON-encoded Avro data is not supported.Syntax
AWS_ROLE_ARN, set the optional AWS_ROLE_EXTERNAL_ID to add a customer-controlled condition to your role’s trust policy.
For role-based AWS access you can additionally set an external ID. An external ID is a value you choose and control that AWS checks when Firebolt assumes your role, adding a second condition on top of your account’s unique IAM principal. Configuring one is a recommended best practice. See IAM roles.
Parameters
- When using static credentials:
- The
URLcan be passed as either the first positional parameter or a named parameter - If you provide either
AWS_ACCESS_KEY_IDorAWS_SECRET_ACCESS_KEY, you must provide both - Providing an AWS session token is optional
- Credentials are not required for accessing public buckets
- The
- The
URLalso accepts theupload://scheme to read a file sent in the same HTTP request. See Upload and query local files.
Return Type
The result is a table with data from the Avro files. Columns are read and parsed using their inferred data types based on the Avro schema. All data types are inferred as nullable.When loading multiple files, Firebolt infers the schema from the most recently modified file. The remaining files must have compatible data types. If types vary between files (e.g., a column contains integers in one file but doubles in another, or is numeric in one file but text in another), the inferred schema may not match all files and thus cause data type errors or query failures. In such cases, we recommend defining an explicit schema using either external tables or
COPY FROM into existing tables.Avro Data Type Mapping
READ_AVRO supports all Avro data types with the following mappings:
Special Handling
Maps: Avro maps are converted to arrays of structs with two fields:key: The map key (alwaysTEXT)value: The map value (type depends on the Avro map value type)
- Single-type unions (e.g.,
["string"]): Inferred as the single type directly - Dual-type unions with null (e.g.,
["null", "string"]): Inferred as a single nullable type (TEXTin this case) - Multi-type unions (e.g.,
["string", "int", "record"]): Converted to structs with nullable fields for each possible type
- First occurrence: Uses the Avro type name without suffix (e.g.,
string,int,record) - Subsequent occurrences: Adds suffix
_<i>starting from_1(e.g.,record_1,record_2, etc.)
record, record_1, record_2.
Enums: Avro enums are converted to their string representation.
Null types: The null type is supported both as a standalone column and within unions. Standalone null columns are handled as nullable text columns that are always null. Within unions, null specifies the nullability of the resulting type itself (e.g., ["null", "string"] creates a nullable text field, and ["null", "string", "int"] creates a nullable struct where the entire struct can be null).
Best practices
Firebolt recommends using aLOCATION object to store credentials for authentication.
When using READ_AVRO(), the URL parameter in the location should contain only Avro files (see location table-valued functions).
Examples
Example 1: Simple Avro file The following code example reads from a simple Avro file with basic data types:
Example 2: Avro file with maps
This example shows how Avro maps are converted to arrays of key-value structs:
Example 3: Avro file with unions
This example demonstrates how Avro unions are converted to structs with nullable fields:
Example 4: Using location object
The following code example uses a
LOCATION object to store credentials for authentication:
PATTERN parameter with a location object to filter specific files:
This reads only the Avro files matching the pattern
sample_directory_*/*.avro within the location’s base path.
Using URL
- The
URLcan be passed as either the first positional parameter or a named parameter. For example, the following two queries will both read the same file:
- The
urlcan represent a single file or a glob pattern. If a glob pattern is used, all files matching the pattern will be read. A special column$source_file_namecan be used to identify the source file of each row in the result set:
*) can only be used at the end of the path. You can use it with any text before or after, such as *.avro, date=2025*.avro, or data_*.avro.
The pattern will recursively match files in all subdirectories. For example:
firebolt_sample_avro directory and all of its subdirectories.