Skip to content

Commit

Permalink
feat: return null when table ref is None
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 committed Dec 2, 2024
1 parent 7cc2f01 commit 1fafd47
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion wren-core/core/src/mdl/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod table_reference {
};
table_ref.serialize(serializer)
} else {
TableReference::default().serialize(serializer)
serializer.serialize_none()
}
}
}
Expand Down Expand Up @@ -258,3 +258,35 @@ impl View {
&self.name
}
}

#[cfg(test)]
mod tests {
use crate::mdl::manifest::table_reference;
use serde_json::Serializer;

#[test]
fn test_table_reference_serialize() {
[
(
Some("catalog.schema.table".to_string()),
r#"{"catalog":"catalog","schema":"schema","table":"table"}"#,
),
(
Some("schema.table".to_string()),
r#"{"catalog":null,"schema":"schema","table":"table"}"#,
),
(
Some("table".to_string()),
r#"{"catalog":null,"schema":null,"table":"table"}"#,
),
(None, "null"),
]
.iter()
.for_each(|(table_ref, expected)| {
let mut buf = Vec::new();
table_reference::serialize(table_ref, &mut Serializer::new(&mut buf))
.unwrap();
assert_eq!(String::from_utf8(buf).unwrap(), *expected);
});
}
}

0 comments on commit 1fafd47

Please sign in to comment.