Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -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),
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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(_)
Expand All @@ -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(_, _)
Expand Down Expand Up @@ -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
Expand Down
258 changes: 258 additions & 0 deletions datafusion/sqllogictest/test_files/ddl.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down