ZENOTME commented on code in PR #20: URL: https://github.com/apache/iceberg-rust/pull/20#discussion_r1282632185
########## crates/iceberg/src/spec/values.rs: ########## @@ -0,0 +1,417 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +/*! + * Value in iceberg + */ + +use std::{any::Any, collections::HashMap, fmt, ops::Deref}; + +use rust_decimal::Decimal; +use serde::{ + de::{MapAccess, Visitor}, + ser::SerializeStruct, + Deserialize, Deserializer, Serialize, +}; +use serde_bytes::ByteBuf; + +use crate::Error; + +use super::datatypes::{PrimitiveType, Type}; + +/// Values present in iceberg type +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(untagged)] +pub enum Value { + /// 0x00 for false, non-zero byte for true + Boolean(bool), + /// Stored as 4-byte little-endian + Int(i32), + /// Stored as 8-byte little-endian + LongInt(i64), + /// Stored as 4-byte little-endian + Float(f32), Review Comment: We need OrderedFloat if we want to impl Hash in Value directly. 1. When we do partition value specific ordering/ [hash](https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements:~:text=hashLong(doubleToLongBits(double(v)))), we can wrap value a type to implement specific Ord/Hash. Like: `Struct ValueForPartitionHash(Value)`. So in this case we may can avoid to impl Hash in Value directly. 2. There is a case maybe we need Hash directly in value: In partition write, we need to split the Record according StructValue, which work like the aggregation. 1. We can process it like the sort agg so that we don't need Hash. 2. If we process it like the hash agg, we need hash the StructValue. (But we also can serialize it first so that we don't need impl Hash in value.🥵 Anyway, I think it related to how we want to implement the partition value hash and partition write. Maybe can let it be f32 first. ########## crates/iceberg/src/spec/values.rs: ########## @@ -0,0 +1,417 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +/*! + * Value in iceberg + */ + +use std::{any::Any, collections::HashMap, fmt, ops::Deref}; + +use rust_decimal::Decimal; +use serde::{ + de::{MapAccess, Visitor}, + ser::SerializeStruct, + Deserialize, Deserializer, Serialize, +}; +use serde_bytes::ByteBuf; + +use crate::Error; + +use super::datatypes::{PrimitiveType, Type}; + +/// Values present in iceberg type +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(untagged)] +pub enum Value { + /// 0x00 for false, non-zero byte for true + Boolean(bool), + /// Stored as 4-byte little-endian + Int(i32), + /// Stored as 8-byte little-endian + LongInt(i64), + /// Stored as 4-byte little-endian + Float(f32), Review Comment: We need OrderedFloat if we want to impl Hash in Value directly. 1. When we do partition value specific ordering/ [hash](https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements:~:text=hashLong(doubleToLongBits(double(v)))), we can wrap value a type to implement specific Ord/Hash. Like: `Struct ValueForPartitionHash(Value)`. So in this case we may can avoid to impl Hash in Value directly. 2. There is a case maybe we need Hash directly in value: In partition write, we need to split the Record according StructValue, which work like the aggregation. 1. We can process it like the sort agg so that we don't need Hash. 2. If we process it like the hash agg, we need hash the StructValue. (But we also can serialize it first so that we don't need impl Hash in value.🥵 Anyway, I think it related to how we want to implement the partition value hash and partition write. Maybe can let it be f32 first. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
