Uh oh!
There was an error while loading. Please reload this page.
ARROW-10656: [Rust] Remove Field from (most) DataTypes, add nullability - #8715
ARROW-10656: [Rust] Remove Field from (most) DataTypes, add nullability#8715ch-sc wants to merge 18 commits into
Conversation
| f1.data_type().cmp_type(f2.data_type()) | ||
| } | ||
| (DataType::Struct(f1), DataType::Struct(f2)) => { | ||
| if f1.len() == f2.len() { |
There was a problem hiding this comment.
Can all use the form f1.len() == f2.len() && f1.iter()... without if else
There was a problem hiding this comment.
Yeah that looks much better.
| /// Compares this data type with another data type only based on the data type | ||
| /// including nested data types, but not based on other values. | ||
| pub fn cmp_type(&self, other: &Self) -> bool { |
There was a problem hiding this comment.
maybe equals instead of compare?
There was a problem hiding this comment.
True, cmp() usually returns Ordering.
Hey @ch-sc , thanks for your PR! @nevi-me, could you help here? I am a bit worried about introducing another comparison of datatypes, but I was unable to find anything in the specification stating that a DataType of a ListArray should have a field name. My main concern here is that this change would allow the following: I receive a OTOH, I also understand the motivation for this change: if the field name is irrelevant, then it should not be used in the comparison. My feeling is that if we need to introduce a different comparison, this often hints that there is useless information on the |
alamb
left a comment
There was a problem hiding this comment.
The rationale explained on https://issues.apache.org/jira/browse/ARROW-10656 is helpful background of why this change is proposed (the introduction of Field into LIst types). Thank you 👍
@ch-sc -
- Is the only intended change here to not compare the name of fields? Or do you have other ideas in mind for the future?
- Is it easy to explain in what circumstance you have DataTypes that are the same except for the field name?
I would personally suggest one of the following:
- Keep the comparison code as is (and include the field name) as there is some reasonable story that it is "part" of the type
- Update the
PartialCmpimplementation forDataTypeto ignore Field names for allDataType==DataTypecomparisons
Having two "similar but subtly different" implementations is confusing to me and I feel like it may be confusing to others too
nevi-me
commented
Nov 19, 2020
@jorgecarleitao I've also checked the specification, and it's unclear on what should happen. It looks like the C++ implementation doesn't check the field names (https://github.com/apache/arrow/blob/master/cpp/src/arrow/record_batch.cc). I made the change for IPC integration purposes, as we were failing tests because of field names. I'm trying to think of what the broader implications of this change would be. I'm so far leaning on saying "we need not check the field name when constructing record batches, but for lists and structs, we should continue checking nullability of the I haven't looked at the code yet, but if the change can be isolated to only be used in the Interestingly, I went down this (or similar route) with data type equality, before realising that we needed a One last matter, which might not be a concern, is that in the specification, a
I like this approach from @alamb |
vertexclique
commented
Nov 19, 2020
A very good approach to go forward. I like it. |
ch-sc
commented
Nov 20, 2020
Thank you all for the quick feedback!
Well, I guess what approach to take when comparing depends on the scenario. When calling
Keeping track of such metadata adds complexity to the user especially in nested scenarios. I would assume in the majority of cases this information is not relevant when comparing. BTW this is not restricted to field names only, but also dictionary ids and dictionary ordering. I would second the suggestion from @alamb:
...or have 2 implementations for including metadata or not. I saw a similar approach in C++ for RecordBatch: boolRecordBatch::Equals(constRecordBatch&other, boolcheck_metadata)However, we should be clear to the users what is actually compared and what is not. If we end up in a scenario where some attributes play a role and some do not this is really hard to understand for anyone. |
nevi-me
commented
Nov 21, 2020
One potentially last comment from my side @ch-sc@alamb@jorgecarleitao@vertexclique We should support checking nullability for list and struct fields. This is important when writing batches to IPC and Parquet. I came across an issue regarding the comparison of nested nullable structs, I plan on creating a test case and a PR in the coming days for this. |
jorgecarleitao
commented
Nov 21, 2020
I agree with @alamb and @nevi-me. IMO we must not have a second comparison. Valid options for me:
Along with Hash, equality is one of the most important operations on a @ch-sc , what is your concern with updating |
ch-sc
commented
Nov 21, 2020
@jorgecarleitao no concerns from my side. Though, if nullability was the only reason why |
alamb
commented
Nov 21, 2020
I agree that the current situation is confusing I think the core of the issue is that the "can the field be nullable" is logically part of a I personally think changing |
alamb
left a comment
There was a problem hiding this comment.
Thanks @ch-sc -- I like the DataTypeContext idea -- I left some suggestions on how to fixup the tests.
Another suggestion is on naming -- instead of DataTypeContext perhaps something slightly less generic like DataTypeAndNull could be better
| } | ||
| DataType::List(Box::new(children.get(0).into())) | ||
| let child_field = children.get(0); | ||
| // returning int16 for now, to test, not sure how to get data type |
There was a problem hiding this comment.
Perhaps you could change this entire function to something like
fn get_data_type_context(field: ipc::Field, may_be_dictionary: bool) -> DataTypeContext {
...
}
And then change
pub(crate) fn get_data_type(field: ipc::Field, may_be_dictionary: bool) -> DataType {
get_data_type_context(field, may_be_dictionary).data_type
There was a problem hiding this comment.
Changed it, but seems like some integration tests are still failing. Any ideas?
ch-sc
commented
Nov 24, 2020
@alamb thank you for your feedback. I agree, DataTypeContext is not ideal. What do you think of |
alamb
commented
Nov 24, 2020
@ch-sc -- I think |
alamb
commented
Nov 28, 2020
@ch-sc -- I think this PR needs a rebase against |
andygrove
commented
Nov 29, 2020
nevi-me
commented
Nov 29, 2020
My apologies, I'm not sure of how I missed this. When I merged this, I only saw unrelated failures in CI. |
nevi-me
commented
Nov 30, 2020
ch-sc
commented
Nov 30, 2020
Hey, sorry I didn't look into github last weekend. @nevi-me can you re-open the PR? I'll try to fix the integration tests. |
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
… of github.com:ch-sc/arrow into ARROW-10656-RecordBatch-requires-exact-data-type-match
alamb
commented
Nov 30, 2020
I am sorry I missed the integration test failures on this PR :( |
…ordBatch-requires-exact-data-type-match
ch-sc
commented
Dec 3, 2020
The integration tests are still failling. Based on the error message it looks like fields are not serialized like expected. Therefore, I added manual serialization and deserialization for fields so that the same output is produced like before. That didn't help unfortuately. |
nevi-me
commented
Dec 3, 2020
ch-sc
commented
Dec 3, 2020
No it's not blocking me at the moment. Thank you! |
ch-sc
commented
Dec 14, 2020
Hi @nevi-me, did you have time to look into the failing integration tests? |
nevi-me
commented
Dec 16, 2020
Hey @ch-sc, I'm going to experiment with a slightly different approach, and I'll let you know how that goes. I'm aiming to have that done over the weekend. I ended up not getting enough time last week. |
nevi-me
commented
Dec 29, 2020
Closing in favour of #8988 |
Compare two data types based on types instead of strictly all values.