You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by xu...@apache.org on 2025/01/21 04:43:56 UTC
(iceberg-rust) branch main updated: fix timesmtap_ns serde name and add test case for primitive type serde (#905)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 985c8d90 fix timesmtap_ns serde name and add test case for primitive type serde (#905)
985c8d90 is described below
commit 985c8d904b1e608badde8320cd773d29d05d2fac
Author: ZENOTME <43...@users.noreply.github.com>
AuthorDate: Tue Jan 21 12:43:51 2025 +0800
fix timesmtap_ns serde name and add test case for primitive type serde (#905)
Co-authored-by: ZENOTME <st...@gmail.com>
---
crates/iceberg/src/spec/datatypes.rs | 149 +++++++++++++++++++++++------------
1 file changed, 97 insertions(+), 52 deletions(-)
diff --git a/crates/iceberg/src/spec/datatypes.rs b/crates/iceberg/src/spec/datatypes.rs
index bce10ad5..8b020529 100644
--- a/crates/iceberg/src/spec/datatypes.rs
+++ b/crates/iceberg/src/spec/datatypes.rs
@@ -226,8 +226,10 @@ pub enum PrimitiveType {
/// Timestamp in microsecond precision, with timezone
Timestamptz,
/// Timestamp in nanosecond precision, without timezone
+ #[serde(rename = "timestamp_ns")]
TimestampNs,
/// Timestamp in nanosecond precision with timezone
+ #[serde(rename = "timestamptz_ns")]
TimestamptzNs,
/// Arbitrary-length character sequences encoded in utf-8
String,
@@ -855,64 +857,107 @@ mod tests {
}
#[test]
- fn decimal() {
+ fn primitive_type_serde() {
let record = r#"
- {
- "type": "struct",
- "fields": [
- {
- "id": 1,
- "name": "id",
- "required": true,
- "type": "decimal(9,2)"
- }
- ]
- }
- "#;
-
- check_type_serde(
- record,
- Type::Struct(StructType {
- fields: vec![NestedField::required(
- 1,
- "id",
- Type::Primitive(PrimitiveType::Decimal {
- precision: 9,
- scale: 2,
- }),
- )
- .into()],
- id_lookup: OnceLock::default(),
- name_lookup: OnceLock::default(),
- }),
- )
+ {
+ "type": "struct",
+ "fields": [
+ {"id": 1, "name": "bool_field", "required": true, "type": "boolean"},
+ {"id": 2, "name": "int_field", "required": true, "type": "int"},
+ {"id": 3, "name": "long_field", "required": true, "type": "long"},
+ {"id": 4, "name": "float_field", "required": true, "type": "float"},
+ {"id": 5, "name": "double_field", "required": true, "type": "double"},
+ {"id": 6, "name": "decimal_field", "required": true, "type": "decimal(9,2)"},
+ {"id": 7, "name": "date_field", "required": true, "type": "date"},
+ {"id": 8, "name": "time_field", "required": true, "type": "time"},
+ {"id": 9, "name": "timestamp_field", "required": true, "type": "timestamp"},
+ {"id": 10, "name": "timestamptz_field", "required": true, "type": "timestamptz"},
+ {"id": 11, "name": "timestamp_ns_field", "required": true, "type": "timestamp_ns"},
+ {"id": 12, "name": "timestamptz_ns_field", "required": true, "type": "timestamptz_ns"},
+ {"id": 13, "name": "uuid_field", "required": true, "type": "uuid"},
+ {"id": 14, "name": "fixed_field", "required": true, "type": "fixed[10]"},
+ {"id": 15, "name": "binary_field", "required": true, "type": "binary"},
+ {"id": 16, "name": "string_field", "required": true, "type": "string"}
+ ]
}
-
- #[test]
- fn fixed() {
- let record = r#"
- {
- "type": "struct",
- "fields": [
- {
- "id": 1,
- "name": "id",
- "required": true,
- "type": "fixed[8]"
- }
- ]
- }
- "#;
+ "#;
check_type_serde(
record,
Type::Struct(StructType {
- fields: vec![NestedField::required(
- 1,
- "id",
- Type::Primitive(PrimitiveType::Fixed(8)),
- )
- .into()],
+ fields: vec![
+ NestedField::required(1, "bool_field", Type::Primitive(PrimitiveType::Boolean))
+ .into(),
+ NestedField::required(2, "int_field", Type::Primitive(PrimitiveType::Int))
+ .into(),
+ NestedField::required(3, "long_field", Type::Primitive(PrimitiveType::Long))
+ .into(),
+ NestedField::required(4, "float_field", Type::Primitive(PrimitiveType::Float))
+ .into(),
+ NestedField::required(
+ 5,
+ "double_field",
+ Type::Primitive(PrimitiveType::Double),
+ )
+ .into(),
+ NestedField::required(
+ 6,
+ "decimal_field",
+ Type::Primitive(PrimitiveType::Decimal {
+ precision: 9,
+ scale: 2,
+ }),
+ )
+ .into(),
+ NestedField::required(7, "date_field", Type::Primitive(PrimitiveType::Date))
+ .into(),
+ NestedField::required(8, "time_field", Type::Primitive(PrimitiveType::Time))
+ .into(),
+ NestedField::required(
+ 9,
+ "timestamp_field",
+ Type::Primitive(PrimitiveType::Timestamp),
+ )
+ .into(),
+ NestedField::required(
+ 10,
+ "timestamptz_field",
+ Type::Primitive(PrimitiveType::Timestamptz),
+ )
+ .into(),
+ NestedField::required(
+ 11,
+ "timestamp_ns_field",
+ Type::Primitive(PrimitiveType::TimestampNs),
+ )
+ .into(),
+ NestedField::required(
+ 12,
+ "timestamptz_ns_field",
+ Type::Primitive(PrimitiveType::TimestamptzNs),
+ )
+ .into(),
+ NestedField::required(13, "uuid_field", Type::Primitive(PrimitiveType::Uuid))
+ .into(),
+ NestedField::required(
+ 14,
+ "fixed_field",
+ Type::Primitive(PrimitiveType::Fixed(10)),
+ )
+ .into(),
+ NestedField::required(
+ 15,
+ "binary_field",
+ Type::Primitive(PrimitiveType::Binary),
+ )
+ .into(),
+ NestedField::required(
+ 16,
+ "string_field",
+ Type::Primitive(PrimitiveType::String),
+ )
+ .into(),
+ ],
id_lookup: OnceLock::default(),
name_lookup: OnceLock::default(),
}),