Skip to content
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

Implement Hash for Schema #2183

Merged
merged 1 commit into from Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions arrow/src/datatypes/schema.rs
Expand Up @@ -18,6 +18,7 @@
use std::collections::HashMap;
use std::default::Default;
use std::fmt;
use std::hash::Hash;

use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};
Expand Down Expand Up @@ -356,6 +357,22 @@ impl fmt::Display for Schema {
}
}

// need to implement `Hash` manually because `HashMap` implement Eq but no `Hash`
#[allow(clippy::derive_hash_xor_eq)]
impl Hash for Schema {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.fields.hash(state);

// ensure deterministic key order
let mut keys: Vec<&String> = self.metadata.keys().collect();
keys.sort();
for k in keys {
k.hash(state);
self.metadata.get(k).expect("key valid").hash(state);
}
}
}

#[derive(Deserialize)]
struct MetadataKeyValue {
key: String,
Expand Down