You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/08/19 14:16:50 UTC
(datafusion) 01/01: minor: Add alias of some SQL types (string, binary, uint64) (#24398)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-24398-c429919c7c8bd81e4e687531a609e2380ed60649
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit a40af552bd8681f1de0cebfeee8bd6e2f93e201b
Author: Nuno Faria <nu...@gmail.com>
AuthorDate: Wed Aug 19 14:12:51 2026 +0000
minor: Add alias of some SQL types (string, binary, uint64) (#24398)
## Which issue does this PR close?
- N/A.
## Rationale for this change
Some sql-parser types were not being processed in DataFusion. This makes
it so they map to existing types, as is done in other systems.
## What changes are included in this PR?
- `Nvarchar/CharacterVarying/CharVarying` -> string.
- `UBigInt` -> uint64.
- `Blob/Binary/Varbinary/Bytes` -> binary.
- `UTinyInt` -> uint8.
- `USmallInt` -> uint16.
I left `Blob(n)`, `Varbinary(n)`. and `Bytes(n)` to return an error,
since in arrow the limits can't be ensured. We could also accept them,
just like `Varchar(n)`, but we would need probably need a
`support_varchar_with_length` type config for binary types.
## Are these changes tested?
Yes.
## Are there any user-facing changes?
New SQL type alias, but no new types are added.
---
datafusion/sql/src/planner.rs | 32 ++--
datafusion/sqllogictest/test_files/ddl.slt | 258 +++++++++++++++++++++++++++++
2 files changed, 277 insertions(+), 13 deletions(-)
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 7bdeddf379..1db11d66b7 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -715,14 +715,19 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
Ok(DataType::Int32)
}
SQLDataType::BigInt(_) | SQLDataType::Int8(_) => Ok(DataType::Int64),
- SQLDataType::TinyIntUnsigned(_) => Ok(DataType::UInt8),
- SQLDataType::SmallIntUnsigned(_) | SQLDataType::Int2Unsigned(_) => {
+ SQLDataType::TinyIntUnsigned(_) | SQLDataType::UTinyInt => Ok(DataType::UInt8),
+ SQLDataType::SmallIntUnsigned(_)
+ | SQLDataType::Int2Unsigned(_)
+ | SQLDataType::USmallInt => {
Ok(DataType::UInt16)
}
SQLDataType::IntUnsigned(_)
| SQLDataType::IntegerUnsigned(_)
| SQLDataType::Int4Unsigned(_) => Ok(DataType::UInt32),
- SQLDataType::Varchar(length) => {
+ SQLDataType::Varchar(length)
+ | SQLDataType::Nvarchar(length)
+ | SQLDataType::CharacterVarying(length)
+ | SQLDataType::CharVarying(length) => {
match (length, self.options.support_varchar_with_length) {
(Some(_), false) => plan_err!(
"does not support Varchar with length, \
@@ -737,11 +742,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}
}
- SQLDataType::BigIntUnsigned(_) | SQLDataType::Int8Unsigned(_) => {
+ SQLDataType::BigIntUnsigned(_)
+ | SQLDataType::Int8Unsigned(_)
+ | SQLDataType::UBigInt => {
Ok(DataType::UInt64)
}
- SQLDataType::Float(_) => Ok(DataType::Float32),
- SQLDataType::Real | SQLDataType::Float4 => Ok(DataType::Float32),
+ SQLDataType::Float(_)
+ | SQLDataType::Real
+ | SQLDataType::Float4 => Ok(DataType::Float32),
SQLDataType::Double(ExactNumberInfo::None)
| SQLDataType::DoublePrecision
| SQLDataType::Float8 => Ok(DataType::Float64),
@@ -804,7 +812,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
};
make_decimal_type(precision, scale.map(|s| s as u64))
}
- SQLDataType::Bytea => Ok(DataType::Binary),
+ SQLDataType::Bytea
+ | SQLDataType::Blob(None)
+ | SQLDataType::Binary(None)
+ | SQLDataType::Varbinary(None)
+ | SQLDataType::Bytes(None) => Ok(DataType::Binary),
SQLDataType::Interval { fields, precision } => {
if fields.is_some() || precision.is_some() {
return not_impl_err!("Unsupported SQL type {sql_type}");
@@ -836,7 +848,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let entries = DataType::Struct(Fields::from([key_field, value_field]));
Ok(DataType::Map(Arc::new(Field::new("entries", entries, false)), false))
}
- SQLDataType::Nvarchar(_)
| SQLDataType::JSON
| SQLDataType::Uuid
| SQLDataType::Binary(_)
@@ -851,8 +862,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
| SQLDataType::MediumInt(_)
| SQLDataType::MediumIntUnsigned(_)
| SQLDataType::Character(_)
- | SQLDataType::CharacterVarying(_)
- | SQLDataType::CharVarying(_)
| SQLDataType::CharacterLargeObject(_)
| SQLDataType::CharLargeObject(_)
| SQLDataType::Timestamp(_, _)
@@ -901,11 +910,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
| SQLDataType::AnyType
| SQLDataType::Table(_)
| SQLDataType::VarBit(_)
- | SQLDataType::UTinyInt
- | SQLDataType::USmallInt
| SQLDataType::HugeInt
| SQLDataType::UHugeInt
- | SQLDataType::UBigInt
| SQLDataType::TimestampNtz{..}
| SQLDataType::NamedTable { .. }
| SQLDataType::TsVector
diff --git a/datafusion/sqllogictest/test_files/ddl.slt b/datafusion/sqllogictest/test_files/ddl.slt
index 487786e3af..1d1f8ff7d8 100644
--- a/datafusion/sqllogictest/test_files/ddl.slt
+++ b/datafusion/sqllogictest/test_files/ddl.slt
@@ -1003,6 +1003,264 @@ statement ok
DROP TABLE dup_src;
+# Test string type aliases
+statement ok
+create table t (
+ a varchar,
+ b varchar(10),
+ c character varying,
+ d character varying(10),
+ e char varying,
+ f char varying(10),
+ g nvarchar,
+ h nvarchar(10),
+ i string,
+ j string(10)
+);
+
+query TTT
+describe t;
+----
+a Utf8View YES
+b Utf8View YES
+c Utf8View YES
+d Utf8View YES
+e Utf8View YES
+f Utf8View YES
+g Utf8View YES
+h Utf8View YES
+i Utf8View YES
+j Utf8View YES
+
+statement ok
+drop table t;
+
+# Test binary type aliases
+statement ok
+create table t (
+ a bytea,
+ b blob,
+ c binary,
+ d varbinary,
+ e bytes
+);
+
+query TTT
+describe t;
+----
+a Binary YES
+b Binary YES
+c Binary YES
+d Binary YES
+e Binary YES
+
+statement ok
+drop table t;
+
+# Test bool type aliases
+statement ok
+create table t (
+ a boolean,
+ b bool
+);
+
+query TTT
+describe t;
+----
+a Boolean YES
+b Boolean YES
+
+statement ok
+drop table t;
+
+# Test int16 type aliases
+statement ok
+create table t (
+ a smallint,
+ b int2
+);
+
+query TTT
+describe t;
+----
+a Int16 YES
+b Int16 YES
+
+statement ok
+drop table t;
+
+# Test int32 type aliases
+statement ok
+create table t (
+ a int,
+ b integer,
+ c int4
+);
+
+query TTT
+describe t;
+----
+a Int32 YES
+b Int32 YES
+c Int32 YES
+
+statement ok
+drop table t;
+
+# Test int64 type aliases
+statement ok
+create table t (
+ a bigint,
+ b int8
+);
+
+query TTT
+describe t;
+----
+a Int64 YES
+b Int64 YES
+
+statement ok
+drop table t;
+
+# Test uint8 type aliases
+statement ok
+create table t (
+ a tinyint unsigned,
+ b utinyint
+);
+
+query TTT
+describe t;
+----
+a UInt8 YES
+b UInt8 YES
+
+statement ok
+drop table t;
+
+# Test uint16 type aliases
+statement ok
+create table t (
+ a smallint unsigned,
+ b int2 unsigned,
+ c usmallint
+);
+
+query TTT
+describe t;
+----
+a UInt16 YES
+b UInt16 YES
+c UInt16 YES
+
+statement ok
+drop table t;
+
+# Test uint32 type aliases
+statement ok
+create table t (
+ a int unsigned,
+ b integer unsigned,
+ c int4 unsigned
+);
+
+query TTT
+describe t;
+----
+a UInt32 YES
+b UInt32 YES
+c UInt32 YES
+
+statement ok
+drop table t;
+
+# Test uint64 type aliases
+statement ok
+create table t (
+ a int8 unsigned,
+ b bigint unsigned,
+ c ubigint
+);
+
+query TTT
+describe t;
+----
+a UInt64 YES
+b UInt64 YES
+c UInt64 YES
+
+statement ok
+drop table t;
+
+# Test float32 type aliases
+statement ok
+create table t (
+ a float,
+ b float4,
+ c real
+);
+
+query TTT
+describe t;
+----
+a Float32 YES
+b Float32 YES
+c Float32 YES
+
+statement ok
+drop table t;
+
+# Test float64 type aliases
+statement ok
+create table t (
+ a double,
+ b double precision,
+ c float8
+);
+
+query TTT
+describe t;
+----
+a Float64 YES
+b Float64 YES
+c Float64 YES
+
+statement ok
+drop table t;
+
+# Test decimal128 type aliases
+statement ok
+create table t (
+ a decimal(10, 2),
+ b numeric(10, 2)
+);
+
+query TTT
+describe t;
+----
+a Decimal128(10, 2) YES
+b Decimal128(10, 2) YES
+
+statement ok
+drop table t;
+
+# Test decimal256 type aliases
+statement ok
+create table t (
+ a decimal(40, 2),
+ b numeric(40, 2)
+);
+
+query TTT
+describe t;
+----
+a Decimal256(40, 2) YES
+b Decimal256(40, 2) YES
+
+statement ok
+drop table t;
+
# Table with Map types
statement ok
create table t (a map(int, int), b map(varchar, map(varchar, int)));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org