Skip to content

Unexpected Null behavior for ScalarValue::partial_cmp() #19579

@2010YOUY01

Description

@2010YOUY01

Describe the bug

For partial_cmp() function for ScalarValue

impl PartialOrd for ScalarValue {

The current behavior is unexpected:

// this test can be added to the above file that `partial_cmp()` lives
    #[test]
    fn scalar_partial_ordering_nulls() {
        use ScalarValue::*;

        assert_eq!(
            Int32(Some(3)).partial_cmp(&Int32(None)),
            Some(Ordering::Greater)
        );
        assert_eq!(
            Int32(None).partial_cmp(&Int32(Some(3))),
            Some(Ordering::Less)
        );
    } 

The comparison between ScalarValue { type: Int32, val: 3 } and ScalarValue { type: Int32, val: Null } returns Some(_), whereas I expected None, indicating that the values are not comparable, consistent with SQL’s three-valued logic.

Additionally, comparing Null with Null returns Some(Ordering::Equal) instead of None.

We should either:

  1. Fix this behavior to follow SQL’s null comparison semantics, or
  2. If this non-standard null behavior is intentional for specific reasons, explicitly document it in the comments.

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions