JanKaul commented on code in PR #29:
URL: https://github.com/apache/iceberg-rust/pull/29#discussion_r1297215097
##########
crates/iceberg/src/spec/schema.rs:
##########
@@ -609,13 +611,88 @@ impl SchemaVisitor for IndexByName {
}
}
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
+#[serde(rename_all = "kebab-case")]
+/// Names and types of fields in a table.
+pub(crate) struct SchemaV2 {
+ /// Identifier of the schema
+ pub schema_id: i32,
+ /// Set of primitive fields that identify rows in a table.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub identifier_field_ids: Option<Vec<i32>>,
+
+ #[serde(flatten)]
+ /// The struct fields
+ pub fields: StructType,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
+#[serde(rename_all = "kebab-case")]
+/// Names and types of fields in a table.
+pub(crate) struct SchemaV1 {
+ /// Identifier of the schema
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub schema_id: Option<i32>,
+ /// Set of primitive fields that identify rows in a table.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub identifier_field_ids: Option<Vec<i32>>,
+
+ #[serde(flatten)]
+ /// The struct fields
+ pub fields: StructType,
+}
+
+impl TryFrom<SchemaV2> for Schema {
+ type Error = Error;
+ fn try_from(value: SchemaV2) -> Result<Self> {
+ Schema::builder()
+ .with_schema_id(value.schema_id)
+ .with_fields(value.fields.fields().iter().cloned())
+
.with_identifier_field_ids(value.identifier_field_ids.unwrap_or_default())
+ .build()
+ }
+}
+
+impl TryFrom<SchemaV1> for Schema {
+ type Error = Error;
+ fn try_from(value: SchemaV1) -> Result<Self> {
+ Schema::builder()
+ .with_schema_id(value.schema_id.unwrap_or(DEFAULT_SCHEMA_ID))
Review Comment:
This is called when deserializing a v1 schema into the general `Schema`
struct. If the v1 schema doesn't have a schema id, we assign a default
schema_id on read.
--
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]