waitingkuo commented on code in PR #4107:
URL: https://github.com/apache/arrow-datafusion/pull/4107#discussion_r1015243156


##########
datafusion/sql/src/planner.rs:
##########
@@ -2808,105 +2918,6 @@ fn extract_possible_join_keys(
     }
 }
 
-/// Convert SQL simple data type to relational representation of data type
-pub fn convert_simple_data_type(sql_type: &SQLDataType) -> Result<DataType> {
-    match sql_type {
-        SQLDataType::Boolean => Ok(DataType::Boolean),
-        SQLDataType::TinyInt(_) => Ok(DataType::Int8),
-        SQLDataType::SmallInt(_) => Ok(DataType::Int16),
-        SQLDataType::Int(_) | SQLDataType::Integer(_) => Ok(DataType::Int32),
-        SQLDataType::BigInt(_) => Ok(DataType::Int64),
-        SQLDataType::UnsignedTinyInt(_) => Ok(DataType::UInt8),
-        SQLDataType::UnsignedSmallInt(_) => Ok(DataType::UInt16),
-        SQLDataType::UnsignedInt(_) | SQLDataType::UnsignedInteger(_) => {
-            Ok(DataType::UInt32)
-        }

Review Comment:
   @alamb i deleted it 



##########
datafusion/core/tests/sql/set_variable.rs:
##########
@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
 
 #[tokio::test]
 async fn set_time_zone() {
-    // we don't support changing time zone for now until all time zone issues 
fixed and related function completed
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    let ctx = SessionContext::new();
+    plan_and_collect(&ctx, "SET datafusion.execution.time_zone = '+08:00'")
+        .await
+        .unwrap();
 
-    // for full variable name
-    let err = plan_and_collect(&ctx, "set datafusion.execution.time_zone = 
'8'")
+    let result = plan_and_collect(&ctx, "SHOW datafusion.execution.time_zone")
         .await
-        .unwrap_err();
+        .unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+#[tokio::test]
+async fn set_time_zone_with_alias_variable_name() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    // for alias time zone
-    let err = plan_and_collect(&ctx, "set time zone = '8'")
+    // TIME ZONE with space
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIME ZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
 
-    // for alias timezone
-    let err = plan_and_collect(&ctx, "set timezone = '8'")
+    // TIMEZONE without space
+    plan_and_collect(&ctx, "SET TIMEZONE = '+07:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIMEZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +07:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_good_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];

Review Comment:
   ideally we could change this to `'2000-01-01T00:00:00'::TIMESTAMPTZ` once 
it's added in the casting kernel (in arrow-rs)



##########
datafusion/core/tests/sql/set_variable.rs:
##########
@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
 
 #[tokio::test]
 async fn set_time_zone() {
-    // we don't support changing time zone for now until all time zone issues 
fixed and related function completed
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    let ctx = SessionContext::new();
+    plan_and_collect(&ctx, "SET datafusion.execution.time_zone = '+08:00'")
+        .await
+        .unwrap();
 
-    // for full variable name
-    let err = plan_and_collect(&ctx, "set datafusion.execution.time_zone = 
'8'")
+    let result = plan_and_collect(&ctx, "SHOW datafusion.execution.time_zone")
         .await
-        .unwrap_err();
+        .unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+#[tokio::test]
+async fn set_time_zone_with_alias_variable_name() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    // for alias time zone
-    let err = plan_and_collect(&ctx, "set time zone = '8'")
+    // TIME ZONE with space
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIME ZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
 
-    // for alias timezone
-    let err = plan_and_collect(&ctx, "set timezone = '8'")
+    // TIMEZONE without space
+    plan_and_collect(&ctx, "SET TIMEZONE = '+07:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIMEZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +07:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_good_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
+        .await
+        .unwrap();

Review Comment:
   test cases for good time zone format
   



##########
datafusion/core/tests/sql/set_variable.rs:
##########
@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
 
 #[tokio::test]
 async fn set_time_zone() {
-    // we don't support changing time zone for now until all time zone issues 
fixed and related function completed
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    let ctx = SessionContext::new();
+    plan_and_collect(&ctx, "SET datafusion.execution.time_zone = '+08:00'")
+        .await
+        .unwrap();
 
-    // for full variable name
-    let err = plan_and_collect(&ctx, "set datafusion.execution.time_zone = 
'8'")
+    let result = plan_and_collect(&ctx, "SHOW datafusion.execution.time_zone")
         .await
-        .unwrap_err();
+        .unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+#[tokio::test]
+async fn set_time_zone_with_alias_variable_name() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    // for alias time zone
-    let err = plan_and_collect(&ctx, "set time zone = '8'")
+    // TIME ZONE with space
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIME ZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
 
-    // for alias timezone
-    let err = plan_and_collect(&ctx, "set timezone = '8'")
+    // TIMEZONE without space
+    plan_and_collect(&ctx, "SET TIMEZONE = '+07:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIMEZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +07:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_good_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '-08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 1999-12-31T16:00:00-08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+0800'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_bad_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00:00'")
+        .await
+        .unwrap();

Review Comment:
   test cases for bad time zone format



##########
datafusion/sql/src/planner.rs:
##########
@@ -2671,6 +2667,120 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             Ok(lit(ScalarValue::new_list(Some(values), data_type)))
         }
     }
+
+    fn convert_data_type(&self, sql_type: &SQLDataType) -> Result<DataType> {
+        match sql_type {
+            SQLDataType::Array(inner_sql_type) => {
+                let data_type = self.convert_simple_data_type(inner_sql_type)?;
+
+                Ok(DataType::List(Box::new(Field::new(
+                    "field", data_type, true,
+                ))))
+            }
+            other => self.convert_simple_data_type(other),
+        }
+    }
+    fn convert_simple_data_type(&self, sql_type: &SQLDataType) -> 
Result<DataType> {
+        match sql_type {
+            SQLDataType::Boolean => Ok(DataType::Boolean),
+            SQLDataType::TinyInt(_) => Ok(DataType::Int8),
+            SQLDataType::SmallInt(_) => Ok(DataType::Int16),
+            SQLDataType::Int(_) | SQLDataType::Integer(_) => 
Ok(DataType::Int32),
+            SQLDataType::BigInt(_) => Ok(DataType::Int64),
+            SQLDataType::UnsignedTinyInt(_) => Ok(DataType::UInt8),
+            SQLDataType::UnsignedSmallInt(_) => Ok(DataType::UInt16),
+            SQLDataType::UnsignedInt(_) | SQLDataType::UnsignedInteger(_) => {
+                Ok(DataType::UInt32)
+            }
+            SQLDataType::UnsignedBigInt(_) => Ok(DataType::UInt64),
+            SQLDataType::Float(_) => Ok(DataType::Float32),
+            SQLDataType::Real => Ok(DataType::Float32),
+            SQLDataType::Double | SQLDataType::DoublePrecision => 
Ok(DataType::Float64),
+            SQLDataType::Char(_)
+            | SQLDataType::Varchar(_)
+            | SQLDataType::Text
+            | SQLDataType::String => Ok(DataType::Utf8),
+            SQLDataType::Timestamp(tz_info) => {
+                let tz = if matches!(tz_info, TimezoneInfo::Tz)
+                    || matches!(tz_info, TimezoneInfo::WithTimeZone)
+                {
+                    // Timestamp With Time Zone
+                    // INPUT : [SQLDataType]   TimestampTz + [RuntimeConfig] 
Time Zone
+                    // OUTPUT: [ArrowDataType] Timestamp<TimeUnit, Some(Time 
Zone)>
+                    match self
+                        .schema_provider
+                        .get_config_option("datafusion.execution.time_zone")
+                    {
+                        Some(ScalarValue::Utf8(s)) => s,
+                        Some(v) => {
+                            return Err(DataFusionError::Internal(format!(
+                                "Incorrect data type for time_zone: {}",
+                                v.get_datatype(),
+                            )))
+                        }
+                        None => return Err(DataFusionError::Internal(format!(
+                            "Config Option datafusion.execution.time_zone 
doesn't exist"
+                        ))),

Review Comment:
   `ScalarValue::UTF8` -> `Option<String>`
   other `ScalarValue` ->  `Err`
   `None` (variable name doen't exsit) -> `Err`



##########
datafusion/core/tests/sql/set_variable.rs:
##########
@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
 
 #[tokio::test]
 async fn set_time_zone() {
-    // we don't support changing time zone for now until all time zone issues 
fixed and related function completed
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    let ctx = SessionContext::new();
+    plan_and_collect(&ctx, "SET datafusion.execution.time_zone = '+08:00'")
+        .await
+        .unwrap();
 
-    // for full variable name
-    let err = plan_and_collect(&ctx, "set datafusion.execution.time_zone = 
'8'")
+    let result = plan_and_collect(&ctx, "SHOW datafusion.execution.time_zone")
         .await
-        .unwrap_err();
+        .unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+#[tokio::test]
+async fn set_time_zone_with_alias_variable_name() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    // for alias time zone
-    let err = plan_and_collect(&ctx, "set time zone = '8'")
+    // TIME ZONE with space
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIME ZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
 
-    // for alias timezone
-    let err = plan_and_collect(&ctx, "set timezone = '8'")
+    // TIMEZONE without space
+    plan_and_collect(&ctx, "SET TIMEZONE = '+07:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIMEZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +07:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_good_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed

Review Comment:
   note that these test cases might need to be modified after 
https://github.com/apache/arrow-rs/issues/1936 fixed. I added a message here



##########
datafusion/core/tests/sql/set_variable.rs:
##########
@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
 
 #[tokio::test]
 async fn set_time_zone() {
-    // we don't support changing time zone for now until all time zone issues 
fixed and related function completed
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    let ctx = SessionContext::new();
+    plan_and_collect(&ctx, "SET datafusion.execution.time_zone = '+08:00'")
+        .await
+        .unwrap();
 
-    // for full variable name
-    let err = plan_and_collect(&ctx, "set datafusion.execution.time_zone = 
'8'")
+    let result = plan_and_collect(&ctx, "SHOW datafusion.execution.time_zone")
         .await
-        .unwrap_err();
+        .unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+#[tokio::test]
+async fn set_time_zone_with_alias_variable_name() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
 
-    // for alias time zone
-    let err = plan_and_collect(&ctx, "set time zone = '8'")
+    // TIME ZONE with space
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIME ZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +08:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
 
-    // for alias timezone
-    let err = plan_and_collect(&ctx, "set timezone = '8'")
+    // TIMEZONE without space
+    plan_and_collect(&ctx, "SET TIMEZONE = '+07:00'")
         .await
-        .unwrap_err();
+        .unwrap();
 
-    assert_eq!(
-        err.to_string(),
-        "Error during planning: Changing Time Zone isn't supported yet"
-    );
+    let result = plan_and_collect(&ctx, "SHOW TIMEZONE").await.unwrap();
+    let expected = vec![
+        "+--------------------------------+---------+",
+        "| name                           | setting |",
+        "+--------------------------------+---------+",
+        "| datafusion.execution.time_zone | +07:00  |",
+        "+--------------------------------+---------+",
+    ];
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_good_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '-08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 1999-12-31T16:00:00-08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+0800'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\") |",
+        "+-----------------------------+",
+        "| 2000-01-01T08:00:00+08:00   |",
+        "+-----------------------------+",
+    ];
+    // this might break once https://github.com/apache/arrow-rs/issues/1936 
fixed
+    assert_batches_eq!(expected, &result);
+}
+
+#[tokio::test]
+async fn set_time_zone_bad_time_zone_format() {
+    let ctx =
+        
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '+08:00:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-----------------------------------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\")                         |",
+        "+-----------------------------------------------------+",
+        "| 2000-01-01T00:00:00 (Unknown Time Zone '+08:00:00') |",
+        "+-----------------------------------------------------+",
+    ];
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '08:00'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-------------------------------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\")                     |",
+        "+-------------------------------------------------+",
+        "| 2000-01-01T00:00:00 (Unknown Time Zone '08:00') |",
+        "+-------------------------------------------------+",
+    ];
+    assert_batches_eq!(expected, &result);
+
+    plan_and_collect(&ctx, "SET TIME ZONE = '08'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+----------------------------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\")                  |",
+        "+----------------------------------------------+",
+        "| 2000-01-01T00:00:00 (Unknown Time Zone '08') |",
+        "+----------------------------------------------+",
+    ];
+    assert_batches_eq!(expected, &result);
+
+    // we dont support named time zone yet
+    plan_and_collect(&ctx, "SET TIME ZONE = 'Asia/Taipei'")
+        .await
+        .unwrap();
+
+    // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the 
middle layer for now
+    let result =
+        plan_and_collect(&ctx, "SELECT 
'2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ")
+            .await
+            .unwrap();
+    let expected = vec![
+        "+-------------------------------------------------------+",
+        "| Utf8(\"2000-01-01T00:00:00\")                           |",
+        "+-------------------------------------------------------+",
+        "| 2000-01-01T00:00:00 (Unknown Time Zone 'Asia/Taipei') |",
+        "+-------------------------------------------------------+",
+    ];
+    assert_batches_eq!(expected, &result);

Review Comment:
   @avantgardnerio 
   based on the discussion here 
https://github.com/apache/arrow-datafusion/issues/4106#issuecomment-1303856668
   
   named timezone like `America/Denver` or `Asia/Taipei` won't be supported in 
this pr



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to