Data Types#
DataFusion uses Arrow, and thus the Arrow type system, for query
execution. The SQL types from
sqlparser-rs
are mapped to Arrow data types according to the following table.
This mapping occurs when defining the schema in a CREATE EXTERNAL TABLE command or when performing a SQL CAST operation.
For background on extension types and custom metadata, see the Implementing User Defined Types and Custom Metadata in DataFusion blog.
You can see the corresponding Arrow type for any SQL expression using
the arrow_typeof function. For example:
select arrow_typeof(interval '1 month');
+---------------------------------------------------------------------+
| arrow_typeof(IntervalMonthDayNano("79228162514264337593543950336")) |
+---------------------------------------------------------------------+
| Interval(MonthDayNano) |
+---------------------------------------------------------------------+
You can cast a SQL expression to a specific Arrow type using the arrow_cast function
For example, to cast the output of now() to a Timestamp with second precision:
select arrow_cast(now(), 'Timestamp(s)') as "now()";
+---------------------+
| now() |
+---------------------+
| 2025-10-24T20:02:45 |
+---------------------+
The older syntax still works as well:
select arrow_cast(now(), 'Timestamp(Second, None)') as "now()";
+---------------------+
| now() |
+---------------------+
| 2023-03-03T17:19:21 |
+---------------------+
Character Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
By default, string types are mapped to Utf8View. This can be configured using the datafusion.sql_parser.map_string_types_to_utf8view setting. When set to false, string types are mapped to Utf8 instead.
Note that CHAR, VARCHAR, STRING, CHARACTER VARYING, CHAR VARYING, and NVARCHAR can
optionally receive the maximum length (e.g., VARCHAR(n)). However, this limit is ignored. To raise
an error when the length is passed, set datafusion.sql_parser.support_varchar_with_length to
false.
Numeric Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The maximum supported precision for DECIMAL types is 76.
Date/Time Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
|
|
|
|
|
|
Boolean Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
Binary Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
|
|
|
|
|
|
|
|
You can create binary literals using a hex string literal such as
X'1234' to create a Binary value of two bytes, 0x12 and 0x34.
Nested Types#
SQL DataType |
Arrow DataType |
|---|---|
|
|
|
|
|
|
|
|
While columns defined with STRUCT require all rows to have the same schema, MAP imposes no such
restriction.
Also note that STRUCT can be declared without defining the field names. In that case, they will be
set to c0, c1, …, cn.
Unsupported SQL Types#
SQL Data Type |
Arrow DataType |
|---|---|
|
Not yet supported |
|
Not yet supported |
|
Not yet supported |
|
Not yet supported |
|
Not yet supported |
|
Not yet supported |
|
Not yet supported |