-
Notifications
You must be signed in to change notification settings - Fork 875
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
Exclude dict_id
and dict_is_ordered
from equality comparison of Field
#1647
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::cmp::Ordering; | ||
use std::collections::BTreeMap; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
use serde_derive::{Deserialize, Serialize}; | ||
use serde_json::{json, Value}; | ||
|
@@ -27,7 +29,7 @@ use super::DataType; | |
/// Contains the meta-data for a single relative type. | ||
/// | ||
/// The `Schema` object is an ordered collection of `Field` objects. | ||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct Field { | ||
name: String, | ||
data_type: DataType, | ||
|
@@ -39,6 +41,50 @@ pub struct Field { | |
metadata: Option<BTreeMap<String, String>>, | ||
} | ||
|
||
impl PartialEq for Field { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.name == other.name | ||
&& self.data_type == other.data_type | ||
&& self.nullable == other.nullable | ||
&& self.metadata == other.metadata | ||
} | ||
} | ||
|
||
impl Eq for Field {} | ||
|
||
impl PartialOrd for Field { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl Ord for Field { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
let mut ord = self.name.cmp(other.name()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.then to make this shorter, but this is also fine |
||
if let Ordering::Equal = ord { | ||
ord = self.data_type.cmp(other.data_type()); | ||
|
||
if let Ordering::Equal = ord { | ||
ord = self.nullable.cmp(&other.nullable); | ||
|
||
if let Ordering::Equal = ord { | ||
ord = self.metadata.cmp(&other.metadata); | ||
} | ||
} | ||
} | ||
ord | ||
} | ||
} | ||
|
||
impl Hash for Field { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.name.hash(state); | ||
self.data_type.hash(state); | ||
self.nullable.hash(state); | ||
self.metadata.hash(state); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a simple test? |
||
impl Field { | ||
/// Creates a new field | ||
pub fn new(name: &str, data_type: DataType, nullable: bool) -> Self { | ||
|
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.
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.
We could probably do with a comment to say why we are implementing these instead of an auto-derive