Skip to content

Commit 53c1a5d

Browse files
committed
add test
1 parent 708609c commit 53c1a5d

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

kernel/src/actions/deletion_vector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::utils::require;
1515
use crate::{DeltaResult, Error, StorageHandler};
1616

1717
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18-
#[cfg_attr(test, derive(serde::Serialize))]
18+
#[cfg_attr(test, derive(serde::Serialize, serde::Deserialize))]
1919
pub enum DeletionVectorStorageType {
2020
#[cfg_attr(test, serde(rename = "u"))]
2121
PersistedRelative,
@@ -58,7 +58,7 @@ impl ToDataType for DeletionVectorStorageType {
5858
}
5959

6060
#[derive(Debug, Clone, PartialEq, Eq, ToSchema)]
61-
#[cfg_attr(test, derive(serde::Serialize), serde(rename_all = "camelCase"))]
61+
#[cfg_attr(test, derive(serde::Serialize, serde::Deserialize), serde(rename_all = "camelCase"))]
6262
pub struct DeletionVectorDescriptor {
6363
/// A single character to indicate how to access the DV. Legal options are: ['u', 'i', 'p'].
6464
pub storage_type: DeletionVectorStorageType,

kernel/src/actions/mod.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,11 @@ impl IntoEngineData for CommitInfo {
706706
}
707707

708708
#[derive(Debug, Clone, PartialEq, Eq, ToSchema)]
709-
#[cfg_attr(test, derive(Serialize, Default), serde(rename_all = "camelCase"))]
709+
#[cfg_attr(
710+
test,
711+
derive(Serialize, Deserialize, Default),
712+
serde(rename_all = "camelCase")
713+
)]
710714
#[internal_api]
711715
pub(crate) struct Add {
712716
/// A relative path to a data file from the root of the table or an absolute path to a file
@@ -2049,4 +2053,50 @@ mod tests {
20492053
let schema = Arc::new(StructType::new_unchecked([]));
20502054
assert!(!schema_contains_file_actions(&schema));
20512055
}
2056+
2057+
fn test_add_tags_deserialization() {
2058+
// Test different cases for the tags field:
2059+
// 1. tags field is null (entire field is None)
2060+
// 2. tags map contains nullable values (some keys map to null)
2061+
// 3. tags map contains non-null string values only
2062+
2063+
// Note about nullable values inside the tags map:
2064+
// The tags field type is Option<HashMap<String, Option<String>>>, which means:
2065+
// - The outer Option makes the entire field nullable (field can be absent or null)
2066+
// - The inner Option<String> makes individual map values nullable (value can be null)
2067+
// This preserves null values in the map, unlike #[allow_null_container_values]
2068+
// which would drop them during materialization.
2069+
2070+
// Case 1: tags field is null
2071+
let json1 = r#"{"path":"file1.parquet","partitionValues":{},"size":100,"modificationTime":1234567890,"dataChange":true,"tags":null}"#;
2072+
let add1: Add = serde_json::from_str(json1).unwrap();
2073+
assert_eq!(add1.tags, None);
2074+
2075+
// Case 2: tags map contains nullable values (some keys map to null)
2076+
let json2 = r#"{"path":"file2.parquet","partitionValues":{},"size":200,"modificationTime":1234567890,"dataChange":true,"tags":{"INSERTION_TIME":"1677811178336000","NULLABLE_TAG":null}}"#;
2077+
let add2: Add = serde_json::from_str(json2).unwrap();
2078+
assert!(add2.tags.is_some());
2079+
let tags = add2.tags.unwrap();
2080+
assert_eq!(tags.len(), 2);
2081+
assert_eq!(
2082+
tags.get("INSERTION_TIME"),
2083+
Some(&Some("1677811178336000".to_string()))
2084+
);
2085+
assert_eq!(tags.get("NULLABLE_TAG"), Some(&None));
2086+
2087+
// Case 3: tags map contains non-null string values only
2088+
let json3 = r#"{"path":"file3.parquet","partitionValues":{},"size":300,"modificationTime":1234567890,"dataChange":true,"tags":{"INSERTION_TIME":"1677811178336000","MIN_INSERTION_TIME":"1677811178336000"}}"#;
2089+
let add3: Add = serde_json::from_str(json3).unwrap();
2090+
assert!(add3.tags.is_some());
2091+
let tags = add3.tags.unwrap();
2092+
assert_eq!(tags.len(), 2);
2093+
assert_eq!(
2094+
tags.get("INSERTION_TIME"),
2095+
Some(&Some("1677811178336000".to_string()))
2096+
);
2097+
assert_eq!(
2098+
tags.get("MIN_INSERTION_TIME"),
2099+
Some(&Some("1677811178336000".to_string()))
2100+
);
2101+
}
20522102
}

0 commit comments

Comments
 (0)