From cd2e32032884268a4278ab315c8a1a6afb088d89 Mon Sep 17 00:00:00 2001 From: Renjie Liu Date: Wed, 9 Aug 2023 19:22:30 +0800 Subject: [PATCH] Resolve conflicts --- crates/iceberg/src/spec/datatypes.rs | 5 -- crates/iceberg/src/spec/values.rs | 79 ++++++++-------------------- 2 files changed, 21 insertions(+), 63 deletions(-) diff --git a/crates/iceberg/src/spec/datatypes.rs b/crates/iceberg/src/spec/datatypes.rs index 6c9f3723c..9b4c986a8 100644 --- a/crates/iceberg/src/spec/datatypes.rs +++ b/crates/iceberg/src/spec/datatypes.rs @@ -22,7 +22,6 @@ use ::serde::de::{MapAccess, Visitor}; use serde::de::{Error, IntoDeserializer}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use std::cell::OnceCell; -use std::slice::Iter; use std::sync::Arc; use std::{collections::HashMap, fmt, ops::Index}; @@ -309,10 +308,6 @@ impl StructType { .get(&field_id) .copied() } - /// Returns an iteratorr over the struct fields - pub fn iter(&self) -> Iter { - self.fields.iter() - } /// Get fields. pub fn fields(&self) -> &[NestedFieldRef] { diff --git a/crates/iceberg/src/spec/values.rs b/crates/iceberg/src/spec/values.rs index 771ffd88e..5d81f95cc 100644 --- a/crates/iceberg/src/spec/values.rs +++ b/crates/iceberg/src/spec/values.rs @@ -407,8 +407,8 @@ impl Literal { }, Type::Struct(schema) => { if let JsonValue::Object(mut object) = value { - Ok(Some(Literal::Struct(Struct::from_iter(schema.iter().map( - |field| { + Ok(Some(Literal::Struct(Struct::from_iter( + schema.fields().iter().map(|field| { ( field.id, object.remove(&field.id.to_string()).and_then(|value| { @@ -423,8 +423,8 @@ impl Literal { }), field.name.clone(), ) - }, - ))))) + }), + )))) } else { Err(Error::new( crate::ErrorKind::DataInvalid, @@ -796,33 +796,9 @@ mod tests { (3, None, "address".to_string()), ])), &Type::Struct(StructType::new(vec![ - NestedField { - id: 1, - name: "id".to_string(), - required: true, - field_type: Box::new(Type::Primitive(PrimitiveType::Int)), - doc: None, - initial_default: None, - write_default: None, - }, - NestedField { - id: 2, - name: "name".to_string(), - required: false, - field_type: Box::new(Type::Primitive(PrimitiveType::String)), - doc: None, - initial_default: None, - write_default: None, - }, - NestedField { - id: 3, - name: "address".to_string(), - required: false, - field_type: Box::new(Type::Primitive(PrimitiveType::String)), - doc: None, - initial_default: None, - write_default: None, - }, + NestedField::required(1, "id", Type::Primitive(PrimitiveType::Int)).into(), + NestedField::optional(2, "name", Type::Primitive(PrimitiveType::String)).into(), + NestedField::optional(3, "address", Type::Primitive(PrimitiveType::String)).into(), ])), ); } @@ -840,15 +816,12 @@ mod tests { None, ]), &Type::List(ListType { - element_field: NestedField { - id: 0, - name: "".to_string(), - required: true, - field_type: Box::new(Type::Primitive(PrimitiveType::Int)), - doc: None, - initial_default: None, - write_default: None, - }, + element_field: NestedField::list_element( + 0, + Type::Primitive(PrimitiveType::Int), + true, + ) + .into(), }), ); } @@ -874,24 +847,14 @@ mod tests { ), ])), &Type::Map(MapType { - key_field: NestedField { - id: 0, - name: "key".to_string(), - required: true, - field_type: Box::new(Type::Primitive(PrimitiveType::String)), - doc: None, - initial_default: None, - write_default: None, - }, - value_field: NestedField { - id: 1, - name: "value".to_string(), - required: true, - field_type: Box::new(Type::Primitive(PrimitiveType::Int)), - doc: None, - initial_default: None, - write_default: None, - }, + key_field: NestedField::map_key_element(0, Type::Primitive(PrimitiveType::String)) + .into(), + value_field: NestedField::map_value_element( + 1, + Type::Primitive(PrimitiveType::Int), + true, + ) + .into(), }), ); }