Skip to content

Conversation

@zjregee
Copy link
Member

@zjregee zjregee commented Jan 21, 2025

Which issue does this PR close?

Closes #14176.

Rationale for this change

What changes are included in this PR?

Add a unified presentation for ColumnarValue.

Are these changes tested?

Yes.

Are there any user-facing changes?

None.

@zjregee
Copy link
Member Author

zjregee commented Jan 21, 2025

cc: @jayzhan211

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this contributon @zjregee -- it looks very close

I think we need to fix the panics in the code, but otherwise it looks great

I also took the liberty to push some tests of this code and merge up from main. Thanks again!


// Implement Display trait for ColumnarValue
//
// # Panics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think it would be surprising of a Display impl panicd.

Instead in this case perhaps we can convert the errors to a string

One way to do that is instead of

pretty_format_columns("ColumnarValue(ArrayRef)", &[Arc::clone(array)])
                    .unwrap()

You can fallback on error like this:

                if let Ok(formatted) = pretty_format_columns("ColumnarValue(ArrayRef)", &[Arc::clone(array)]) {
                    write!(f, "{}", formatted)
                } else {
                    write!(f, "Error formatting columnar value")
                }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help and suggestions, I have fixed this.

Comment on lines 365 to 369
"+----------------------------+\n\
| ColumnarValue(ScalarValue) |\n\
+----------------------------+\n\
| foo |\n\
+----------------------------+"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the format does not align

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the meaning of align here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean every line here doesn't seem to be aligned?

ideally:

            "+----------------------------+\n\
             | ColumnarValue(ScalarValue) |\n\
             +----------------------------+\n\
             | foo                        |\n\
             +----------------------------+"
              ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this, thanks and updated.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

let column = ColumnarValue::from(ScalarValue::from("foo"));
assert_eq!(
column.to_string(),
concat!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ -- TIL "concat!" -- that looks much nicer

@alamb alamb merged commit 774d3cb into apache:main Jan 24, 2025
25 checks passed
@zjregee zjregee deleted the add-display-for-columnar-value branch January 24, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Display for ColumnarValue

4 participants