Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 59 additions & 16 deletions crates/catalog/glue/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl SchemaVisitor for GlueSchemaBuilder {
(ICEBERG_FIELD_ID.to_string(), format!("{}", field.id)),
(
ICEBERG_FIELD_OPTIONAL.to_string(),
format!("{}", field.required).to_lowercase(),
format!("{}", !field.required).to_lowercase(),
),
(
ICEBERG_FIELD_CURRENT.to_string(),
Expand Down Expand Up @@ -209,10 +209,11 @@ mod tests {
name: impl Into<String>,
r#type: impl Into<String>,
id: impl Into<String>,
optional: bool,
) -> Result<Column> {
let parameters = HashMap::from([
(ICEBERG_FIELD_ID.to_string(), id.into()),
(ICEBERG_FIELD_OPTIONAL.to_string(), "true".to_string()),
(ICEBERG_FIELD_OPTIONAL.to_string(), optional.to_string()),
(ICEBERG_FIELD_CURRENT.to_string(), "true".to_string()),
]);

Expand Down Expand Up @@ -318,19 +319,19 @@ mod tests {
let result = GlueSchemaBuilder::from_iceberg(&metadata)?.build();

let expected = vec![
create_column("c1", "boolean", "1")?,
create_column("c2", "int", "2")?,
create_column("c3", "bigint", "3")?,
create_column("c4", "float", "4")?,
create_column("c5", "double", "5")?,
create_column("c6", "decimal(2,2)", "6")?,
create_column("c7", "date", "7")?,
create_column("c8", "string", "8")?,
create_column("c9", "timestamp", "9")?,
create_column("c10", "string", "10")?,
create_column("c11", "string", "11")?,
create_column("c12", "binary", "12")?,
create_column("c13", "binary", "13")?,
create_column("c1", "boolean", "1", false)?,
create_column("c2", "int", "2", false)?,
create_column("c3", "bigint", "3", false)?,
create_column("c4", "float", "4", false)?,
create_column("c5", "double", "5", false)?,
create_column("c6", "decimal(2,2)", "6", false)?,
create_column("c7", "date", "7", false)?,
create_column("c8", "string", "8", false)?,
create_column("c9", "timestamp", "9", false)?,
create_column("c10", "string", "10", false)?,
create_column("c11", "string", "11", false)?,
create_column("c12", "binary", "12", false)?,
create_column("c13", "binary", "13", false)?,
];

assert_eq!(result, expected);
Expand Down Expand Up @@ -378,6 +379,7 @@ mod tests {
"person",
"struct<name:string, age:int>",
"1",
false,
)?];

assert_eq!(result, expected);
Expand Down Expand Up @@ -432,6 +434,7 @@ mod tests {
"location",
"array<struct<latitude:float, longitude:float>>",
"1",
false,
)?];

assert_eq!(result, expected);
Expand Down Expand Up @@ -475,10 +478,50 @@ mod tests {

let result = GlueSchemaBuilder::from_iceberg(&metadata)?.build();

let expected = vec![create_column("quux", "map<string,map<string,int>>", "1")?];
let expected = vec![create_column(
"quux",
"map<string,map<string,int>>",
"1",
false,
)?];

assert_eq!(result, expected);

Ok(())
}

#[test]
fn test_schema_with_optional_fields() -> Result<()> {
let record = r#"{
"type": "struct",
"schema-id": 1,
"fields": [
{
"id": 1,
"name": "required_field",
"required": true,
"type": "string"
},
{
"id": 2,
"name": "optional_field",
"required": false,
"type": "int"
}
]
}"#;

let schema = serde_json::from_str::<Schema>(record)?;
let metadata = create_metadata(schema)?;

let result = GlueSchemaBuilder::from_iceberg(&metadata)?.build();

let expected = vec![
create_column("required_field", "string", "1", false)?,
create_column("optional_field", "int", "2", true)?,
];

assert_eq!(result, expected);
Ok(())
}
}
6 changes: 3 additions & 3 deletions crates/catalog/glue/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub(crate) fn convert_to_glue_table(

let storage_descriptor = StorageDescriptor::builder()
.set_columns(Some(glue_schema))
.location(&metadata_location)
.location(metadata.location().to_string())
.build();

let mut parameters = HashMap::from([
Expand Down Expand Up @@ -345,7 +345,7 @@ mod tests {

let parameters = HashMap::from([
(ICEBERG_FIELD_ID.to_string(), "1".to_string()),
(ICEBERG_FIELD_OPTIONAL.to_string(), "true".to_string()),
(ICEBERG_FIELD_OPTIONAL.to_string(), "false".to_string()),
(ICEBERG_FIELD_CURRENT.to_string(), "true".to_string()),
]);

Expand All @@ -359,7 +359,7 @@ mod tests {

let storage_descriptor = StorageDescriptor::builder()
.set_columns(Some(vec![column]))
.location(&metadata_location)
.location(metadata.location())
.build();

let result =
Expand Down
Loading