Skip to content

Commit

Permalink
Implement Hash for Schema (#2183)
Browse files Browse the repository at this point in the history
Closes #2182.
  • Loading branch information
crepererum committed Jul 28, 2022
1 parent b8e034c commit 6c77cd5
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 6c77cd5

Please sign in to comment.