You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/08/16 00:44:23 UTC

[arrow-datafusion] branch master updated: Support `INTEGER` again in addition to `INT` in `CREATE TABLE` and `CAST` statements (#3167)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 89bcfc482 Support `INTEGER` again in addition to `INT` in `CREATE TABLE` and `CAST` statements (#3167)
89bcfc482 is described below

commit 89bcfc4827a84c37abdf6476ec164611b270492d
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Mon Aug 15 20:44:18 2022 -0400

    Support `INTEGER` again in addition to `INT` in `CREATE TABLE` and `CAST` statements (#3167)
    
    * Update test to fail with INTEGER
    
    * Fix error
    
    * List all unsupported types
---
 datafusion/core/tests/sql/mod.rs |  2 +-
 datafusion/sql/src/planner.rs    | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rs
index 724bdc90d..3e50b4346 100644
--- a/datafusion/core/tests/sql/mod.rs
+++ b/datafusion/core/tests/sql/mod.rs
@@ -631,7 +631,7 @@ async fn register_aggregate_csv_by_sql(ctx: &SessionContext) {
         c2  INT NOT NULL,
         c3  SMALLINT NOT NULL,
         c4  SMALLINT NOT NULL,
-        c5  INT NOT NULL,
+        c5  INTEGER NOT NULL,
         c6  BIGINT NOT NULL,
         c7  SMALLINT NOT NULL,
         c8  INT NOT NULL,
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 9f974aa4c..28c82f802 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -483,7 +483,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
     fn make_data_type(&self, sql_type: &SQLDataType) -> Result<DataType> {
         match sql_type {
             SQLDataType::BigInt(_) => Ok(DataType::Int64),
-            SQLDataType::Int(_) => Ok(DataType::Int32),
+            SQLDataType::Int(_) | SQLDataType::Integer(_) => Ok(DataType::Int32),
             SQLDataType::SmallInt(_) => Ok(DataType::Int16),
             SQLDataType::Char(_) | SQLDataType::Varchar(_) | SQLDataType::Text => {
                 Ok(DataType::Utf8)
@@ -498,7 +498,30 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             SQLDataType::Date => Ok(DataType::Date32),
             SQLDataType::Time => Ok(DataType::Time64(TimeUnit::Nanosecond)),
             SQLDataType::Timestamp => Ok(DataType::Timestamp(TimeUnit::Nanosecond, None)),
-            _ => Err(DataFusionError::NotImplemented(format!(
+            // Explicitly list all other types so that if sqlparser
+            // adds/changes the `SQLDataType` the compiler will tell us on upgrade
+            // and avoid bugs like https://github.com/apache/arrow-datafusion/issues/3059
+            SQLDataType::Nvarchar(_)
+            | SQLDataType::Uuid
+            | SQLDataType::Binary(_)
+            | SQLDataType::Varbinary(_)
+            | SQLDataType::Blob(_)
+            | SQLDataType::TinyInt(_)
+            | SQLDataType::UnsignedTinyInt(_)
+            | SQLDataType::UnsignedSmallInt(_)
+            | SQLDataType::UnsignedInt(_)
+            | SQLDataType::UnsignedInteger(_)
+            | SQLDataType::UnsignedBigInt(_)
+            | SQLDataType::Datetime
+            | SQLDataType::Interval
+            | SQLDataType::Regclass
+            | SQLDataType::String
+            | SQLDataType::Bytea
+            | SQLDataType::Custom(_)
+            | SQLDataType::Array(_)
+            | SQLDataType::Enum(_)
+            | SQLDataType::Set(_)
+            | SQLDataType::Clob(_) => Err(DataFusionError::NotImplemented(format!(
                 "The SQL data type {:?} is not implemented",
                 sql_type
             ))),