You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ch-sc (via GitHub)" <gi...@apache.org> on 2023/10/11 14:02:11 UTC

[PR] Implement Ord for DataType [arrow-rs]

ch-sc opened a new pull request, #4920:
URL: https://github.com/apache/arrow-rs/pull/4920

   # 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 #4919 (Compare `DataType` based on memory size).
   
   # 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 there any user-facing changes?
   
   These changes will alter the way `DataType` is ordered. Users who rely on the current ordering, which is just the basic derived implementation for `Ord`, might be affected.
   
   <!--
   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 `breaking 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@arrow.apache.org

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


Re: [PR] Implement Ord for DataType [arrow-rs]

Posted by "ch-sc (via GitHub)" <gi...@apache.org>.
ch-sc closed pull request #4920: Implement Ord for DataType
URL: https://github.com/apache/arrow-rs/pull/4920


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

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


Re: [PR] Implement Ord for DataType [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4920:
URL: https://github.com/apache/arrow-rs/pull/4920#discussion_r1355107483


##########
arrow-schema/src/datatype.rs:
##########
@@ -310,6 +311,38 @@ impl fmt::Display for DataType {
     }
 }
 
+impl PartialOrd for DataType {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        Some(self.cmp(other))
+    }
+}
+
+impl Ord for DataType {
+    fn cmp(&self, other: &Self) -> Ordering {
+        match (self, other) {
+            (DataType::Null, DataType::Null) => Ordering::Equal,
+            (DataType::Null, _) => Ordering::Less,
+            (_, DataType::Null) => Ordering::Greater,
+            (DataType::Boolean, DataType::Boolean) => Ordering::Equal,
+            (DataType::Boolean, _) => Ordering::Less,
+            (_, DataType::Boolean) => Ordering::Greater,
+            (a, b) => {
+                if a.is_primitive() && b.is_primitive() {
+                    self.primitive_width()
+                        .unwrap_or(0)
+                        .cmp(&other.primitive_width().unwrap_or(0))

Review Comment:
   This is inconsistent with the implementation of Eq and is therefore ill-formed



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

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


Re: [PR] Implement Ord for DataType [arrow-rs]

Posted by "ch-sc (via GitHub)" <gi...@apache.org>.
ch-sc commented on PR #4920:
URL: https://github.com/apache/arrow-rs/pull/4920#issuecomment-1757935069

   Thanks for your feedback @tustvold. I'll do it in DataFusion


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

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