Fokko commented on code in PR #20: URL: https://github.com/apache/iceberg-rust/pull/20#discussion_r1285452552
########## 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), + /// Stored as 8-byte little-endian + Double(f64), + /// Stores days from the 1970-01-01 in an 4-byte little-endian int + Date(i32), + /// Stores microseconds from midnight in an 8-byte little-endian long + Time(i64), + /// Stores microseconds from 1970-01-01 00:00:00.000000 in an 8-byte little-endian long + Timestamp(i64), + /// Stores microseconds from 1970-01-01 00:00:00.000000 in an 8-byte little-endian long + TimestampTZ(i64), Review Comment: > By using chrono Datetime and NaiveTime, our users (and ourselves) will unlikely to use our API in wrong. We don't need to think about it's s, ms or ns. This one is easy since Iceberg only supports microsecond precision. I would still very much opt for just a plain integer. In the user-facing API, I think it is okay to use `chrono`, however, for internal representation, the int64 is much easier because you don't need to do any boxing for comparison. A datetime can be derived from: - **String**: Where we parse the string in the ISO8601 form, and convert it to microseconds since epoch - **Integer/Long**: Where we assume the microseconds since epoch - **chrono**: Where we convert the value into microseconds from epoch. Also, here you could also accept different forms. For example, where the column is a `NaiveDateTime`, we could also accept a `NaiveDate` in an expression. However, I strongly believe that the internal format should be an int/long. For example, in https://github.com/apache/iceberg-rust/pull/20#discussion_r1283454786. Where we read the partition values. For each of the manifest entries, you would need to look up the type and convert it to a date before you could do the comparison. The same case for the metrics evaluator, where we compare a value with the upper- and lower bound of a column to check if it is in range. I think this adds a lot of complexity in quite a hot path, which we should avoid. -- 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]
