-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support parsing and display pretty for StructType #7469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alamb
approved these changes
May 8, 2025
Contributor
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @goldmedal -- this is really nice and very well tested 👍
| ("Decimal128(3, 500)", "Error converting 500 into i8 for Decimal128: out of range integral type conversion attempted"), | ||
| ("Decimal256(3, 500)", "Error converting 500 into i8 for Decimal256: out of range integral type conversion attempted"), | ||
|
|
||
| ("Struct(f1, Int64)", "Error finding next type, got unexpected ','"), |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Contributor
|
Thank you @goldmedal |
Contributor
Author
|
Thanks @alamb |
OussamaSaoudi
added a commit
to delta-io/delta-kernel-rs
that referenced
this pull request
Aug 4, 2025
## What changes are proposed in this pull request? This PR fixes a test that fails on an error message to work across all arrow versions. the error message depends on the Debug print of arrow type. Due to this [commit](apache/arrow-rs#7469), the debug print result differs between arrow versions. ## How was this change tested? existing unit tests. Indentation was tested by breaking a test and checking that the error message is easy to read.
OussamaSaoudi
added a commit
to OussamaSaoudi/delta-kernel-rs
that referenced
this pull request
Aug 8, 2025
…#1135) ## What changes are proposed in this pull request? This PR fixes a test that fails on an error message to work across all arrow versions. the error message depends on the Debug print of arrow type. Due to this [commit](apache/arrow-rs#7469), the debug print result differs between arrow versions. ## How was this change tested? existing unit tests. Indentation was tested by breaking a test and checking that the error message is easy to read.
This was referenced Sep 7, 2025
mbrobbel
pushed a commit
that referenced
this pull request
Sep 23, 2025
This is part of an attempt to improve the error reporting of `arrow-rs`,
`datafusion`, and any other 3rd party crates.
I believe that error messages should be as readable as possible. Aim for
`rustc` more than `gcc`.
Here's an example of how this PR improves some existing error messages:
Before:
> Casting from Map(Field { name: "entries", data_type: Struct([Field {
name: "key", data_type: Utf8, nullable: false, dict_id: 0,
dict_is_ordered: false, metadata: {} }, Field { name: "value",
data_type: Interval(DayTime), nullable: true, dict_id: 0,
dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0,
dict_is_ordered: false, metadata: {} }, false) to Map(Field { name:
"entries", data_type: Struct([Field { name: "key", data_type: Utf8,
nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} },
Field { name: "value", data_type: Duration(Second), nullable: false,
dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false,
dict_id: 0, dict_is_ordered: false, metadata: {} }, true) not supported
After:
> Casting from Map(Field { "entries": Struct(key Utf8, value nullable
Interval(DayTime)) }, false) to Map(Field { "entries": Struct(key Utf8,
value Duration(Second)) }, true) not supported
# Which issue does this PR close?
- Closes #7048
- Continues and closes #7051
- Continues #7469
- More improvements coming in
#8291
- Sibling PR: apache/datafusion#17565
- Part of #8351
# Rationale for this change
DataType:s are often shown in error messages. Making these error
messages readable is _very important_.
# What changes are included in this PR?
## ~Unify `Debug` and `Display`~
~The `Display` and `Debug` of `DataType` are now the SAME.~
~Why? Both are frequently used in error messages (both in arrow, and
`datafusion`), and both benefit from being readable yet reversible.~
Reverted based on PR feedback. I will try to improve the `Debug`
formatting in a future PR, with clever use of
https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_struct
## Improve `Display` of lists
Improve the `Display` formatting of
* `DataType::List`
* `DataType::LargeList`
* `DataType::FixedSizeList`
**Before**: `List(Field { name: \"item\", data_type: Int32, nullable:
true, dict_id: 0, dict_is_ordered: false, metadata: {} })`
**After**: `List(nullable Int32)`
**Before**: `FixedSizeList(Field { name: \"item\", data_type: Int32,
nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, 5)`
**After**: `FixedSizeList(5 x Int32)`
### Better formatting of `DataType::Struct`
The formatting of `Struct` is now reversible, including nullability and
metadata.
- Continues #7469
### ~Improve `Debug` format of `Field`~
~Best understood with this diff for an existing test:~
<img width="1140" height="499" alt="Screenshot 2025-09-07 at 18 30 44"
src="https://github.com/user-attachments/assets/794b4de9-8459-4ee7-82d2-8f5ae248614c"
/>
**EDIT**: reverted
# Are these changes tested?
Yes - new tests cover them
# Are there any user-facing changes?
`Display/to_string` has changed, and so this is a **BREAKING CHANGE**.
Care has been taken that the formatting contains all necessary
information (i.e. is reversible), though the actual `FromStr`
implementation is still not written (it is missing on `main`, and
missing in this PR - so no change).
----
Let me know if I went to far… or not far enough 😆
---------
Co-authored-by: irenjj <renj.jiang@gmail.com>
mbrobbel
pushed a commit
that referenced
this pull request
Sep 25, 2025
# Which issue does this PR close? * Follows #8290 (merge that first, and the diff of this PR will drop) * #7469 * Part of #8351 # Rationale for this change We would previously format structs like so: `Struct(name1 type1, name2 nullable type2)` This will break badly whenever the field name is anything but a simple identifier. In other words: it allows [string injection](https://xkcd.com/327/) if the field name contains an end-paranthesis. Except for that, it is also difficult to debug mistakingly bad field names like " " or "\n". # What changes are included in this PR? We change the `Display` and `Debug` formatting of `Struct` **Before**: `Struct(name1 type1, name2 nullable type2)` **After**: `Struct("name1": type1, "name2": nullable type2)` # Are these changes tested? Yes - I've updated the existing tests. # Are there any user-facing changes? Yes, changing the `Display` formatting is a **breaking change**
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
I implemented the
datatype_parsefor the struct type. I follow the DuckDB SQL style to parse a struct type.The format is
I also implemented the
Displayfor the struct type. The display result is reversible.What changes are included in this PR?
datatype_parsefor StructTypeDisplayfor StructTypeAre there any user-facing changes?
Now, we can parse a text as a struct type.