You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2024/10/25 05:31:19 UTC

[PR] Draft: Logical signature [datafusion]

jayzhan211 opened a new pull request, #13104:
URL: https://github.com/apache/datafusion/pull/13104

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


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

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


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


Re: [PR] Draft: Logical signature [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13104:
URL: https://github.com/apache/datafusion/pull/13104#discussion_r1816025254


##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -506,14 +494,35 @@ fn get_valid_types(
                 );
             }
 
+            let mut new_types = Vec::with_capacity(current_types.len());
             for (data_type, target_type) in current_types.iter().zip(target_types.iter())
             {
-                if !can_cast_types(data_type, target_type) {
-                    return plan_err!("{data_type} is not coercible to {target_type}");
+                if !target_type.can_decode_to(data_type) {
+                    fn search_castable_physical_type(
+                        data_type: &DataType,
+                        target_type: &Arc<dyn LogicalType>,
+                    ) -> Option<DataType> {
+                        for physical_type in target_type.decode_types().iter() {

Review Comment:
   @notfilippo I think we need a way to know the physical types that we are able to casted to given the Logical type.
   
   For example, if we have signature which expect Logical::String, and it accepts not only Utf8, LargeUtf8, Utf8View family but also numeric int, we need to cast the int to string so we need to know the physical types given a logical type.
   
   Therefore, I think we need to add another function that returns the physical type for LogicalType. Note that **the order matters** if we would like the cast to Utf8View then LargeUtf8 and then Utf8 in order.
   
   
   `select div('9', 4);` is the example in postgres that accepts numeric string, I would we may need to accept numeric string as well.
   
   What do you think? It would be nice if there is any other better approach!



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

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


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


Re: [PR] Draft: Logical signature [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13104:
URL: https://github.com/apache/datafusion/pull/13104#discussion_r1816025254


##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -506,14 +494,35 @@ fn get_valid_types(
                 );
             }
 
+            let mut new_types = Vec::with_capacity(current_types.len());
             for (data_type, target_type) in current_types.iter().zip(target_types.iter())
             {
-                if !can_cast_types(data_type, target_type) {
-                    return plan_err!("{data_type} is not coercible to {target_type}");
+                if !target_type.can_decode_to(data_type) {
+                    fn search_castable_physical_type(
+                        data_type: &DataType,
+                        target_type: &Arc<dyn LogicalType>,
+                    ) -> Option<DataType> {
+                        for physical_type in target_type.decode_types().iter() {

Review Comment:
   @notfilippo I think we need a way to know the physical types that we are able to casted to given the Logical type.
   
   For example, if we have signature which expect Logical::String, and it accepts not only Utf8, LargeUtf8, Utf8View family but also numeric int, we need to cast the int to string so we need to know the physical types given a logical type.
   
   Therefore, I think we need to add another function that returns the physical type for LogicalType. Note that **the order matters** if we would like the cast to Utf8View then LargeUtf8 and then Utf8 in order.
   
   
   `select div('9', 4);` is the example in postgres that accepts numeric string, I would we may need to accept numeric string as well.
   
   What do you think? It would be nice if there is any other better approach!



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

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


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


Re: [PR] Draft: Logical signature [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 closed pull request #13104: Draft: Logical signature
URL: https://github.com/apache/datafusion/pull/13104


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

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


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