add eq and hash for datavalue
// See notice.md
use std::fmt;
+use std::hash::Hash;
+use std::hash::Hasher;
use std::sync::Arc;
use common_exception::ErrorCode;
use common_exception::Result;
use common_macros::MallocSizeOf;
+use ordered_float::OrderedFloat;
use serde_json::json;
use crate::prelude::*;
@@ -44,6 +47,28 @@ pub enum DataValue {
Variant(VariantValue),
}
+impl Eq for DataValue {}
+
+#[allow(clippy::derive_hash_xor_eq)]
+impl Hash for DataValue {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ match self {
+ DataValue::Null => (),
+ DataValue::Boolean(v) => v.hash(state),
+ DataValue::Int64(v) => v.hash(state),
+ DataValue::UInt64(v) => v.hash(state),
+ DataValue::Float64(v) => {
+ let v = OrderedFloat::from(*v);
+ v.hash(state)
+ }
+ DataValue::String(v) => v.hash(state),
+ DataValue::Array(v) => v.hash(state),
+ DataValue::Struct(v) => v.hash(state),
+ DataValue::Variant(_) => todo!(),
+ }
+ }
+}
+
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, MallocSizeOf)]
pub enum ValueType {
Null,
