jayzhan211 commented on code in PR #13372:
URL: https://github.com/apache/datafusion/pull/13372#discussion_r1877995285


##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -568,35 +572,63 @@ fn get_valid_types(
             // Make sure the corresponding test is covered
             // If this function becomes COMPLEX, create another new signature!
             fn can_coerce_to(
-                logical_type: &NativeType,
-                target_type: &NativeType,
-            ) -> bool {
-                if logical_type == target_type {
-                    return true;
-                }
+                current_type: &DataType,
+                target_type_class: &TypeSignatureClass,
+            ) -> Result<DataType> {
+                let logical_type: NativeType = current_type.into();
 
-                if logical_type == &NativeType::Null {
-                    return true;
-                }
+                match target_type_class {
+                    TypeSignatureClass::Native(native_type) => {
+                        let target_type = native_type.native();
+                        if &logical_type == target_type {
+                            return target_type.default_cast_for(current_type);
+                        }
 
-                if target_type.is_integer() && logical_type.is_integer() {
-                    return true;
-                }
+                        if logical_type == NativeType::Null {
+                            return target_type.default_cast_for(current_type);
+                        }
+
+                        if target_type.is_integer() && 
logical_type.is_integer() {
+                            return target_type.default_cast_for(current_type);
+                        }
 
-                false
+                        internal_err!(
+                            "Expect {} but received {}",
+                            target_type_class,
+                            current_type
+                        )
+                    }
+                    // Not consistent with Postgres and DuckDB but to avoid 
regression we implicit cast string to timestamp
+                    TypeSignatureClass::Timestamp if logical_type == 
NativeType::String => {
+                        Ok(DataType::Timestamp(TimeUnit::Nanosecond, None))
+                    }
+                    TypeSignatureClass::Timestamp if 
logical_type.is_timestamp() => {

Review Comment:
   timestamp is matched whatever the timezone it has



-- 
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...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to