Skip to content

Commit

Permalink
fix: remove tests upstreamed to kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
roeap committed May 10, 2024
1 parent 3ab0f82 commit cd589f9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 185 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ debug = true
debug = "line-tables-only"

[workspace.dependencies]
delta_kernel = { git = "https://github.com/roeap/delta-kernel-rs", rev = "524262aa74d2f664bc5cc9b9ce06d7c6274bf7f4" }
delta_kernel = { git = "https://github.com/roeap/delta-kernel-rs", rev = "312044f5759f4e38e634d2dbfb62bc9fcd95c471" }

# arrow
arrow = { version = "51" }
Expand Down
184 changes: 0 additions & 184 deletions crates/core/src/kernel/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,190 +137,6 @@ mod tests {
use serde_json;
use serde_json::json;

#[test]
fn test_serde_data_types() {
let data = r#"
{
"name": "a",
"type": "integer",
"nullable": false,
"metadata": {}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();
assert!(matches!(
field.data_type,
DataType::Primitive(PrimitiveType::Integer)
));

let data = r#"
{
"name": "c",
"type": {
"type": "array",
"elementType": "integer",
"containsNull": false
},
"nullable": true,
"metadata": {}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();
assert!(matches!(field.data_type, DataType::Array(_)));

let data = r#"
{
"name": "e",
"type": {
"type": "array",
"elementType": {
"type": "struct",
"fields": [
{
"name": "d",
"type": "integer",
"nullable": false,
"metadata": {}
}
]
},
"containsNull": true
},
"nullable": true,
"metadata": {}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();
assert!(matches!(field.data_type, DataType::Array(_)));
match field.data_type {
DataType::Array(array) => assert!(matches!(array.element_type, DataType::Struct(_))),
_ => unreachable!(),
}

let data = r#"
{
"name": "f",
"type": {
"type": "map",
"keyType": "string",
"valueType": "string",
"valueContainsNull": true
},
"nullable": true,
"metadata": {}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();
assert!(matches!(field.data_type, DataType::Map(_)));
}

#[test]
fn test_roundtrip_decimal() {
let data = r#"
{
"name": "a",
"type": "decimal(10, 2)",
"nullable": false,
"metadata": {}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();
assert!(matches!(
field.data_type,
DataType::Primitive(PrimitiveType::Decimal(10, 2))
));

let json_str = serde_json::to_string(&field).unwrap();
assert_eq!(
json_str,
r#"{"name":"a","type":"decimal(10,2)","nullable":false,"metadata":{}}"#
);
}

#[test]
fn test_invalid_decimal() {
let data = r#"
{
"name": "a",
"type": "decimal(39, 10)",
"nullable": false,
"metadata": {}
}
"#;
assert!(matches!(
serde_json::from_str::<StructField>(data).unwrap_err(),
_
));

let data = r#"
{
"name": "a",
"type": "decimal(10, 39)",
"nullable": false,
"metadata": {}
}
"#;
assert!(matches!(
serde_json::from_str::<StructField>(data).unwrap_err(),
_
));
}

#[test]
fn test_field_metadata() {
let data = r#"
{
"name": "e",
"type": {
"type": "array",
"elementType": {
"type": "struct",
"fields": [
{
"name": "d",
"type": "integer",
"nullable": false,
"metadata": {
"delta.columnMapping.id": 5,
"delta.columnMapping.physicalName": "col-a7f4159c-53be-4cb0-b81a-f7e5240cfc49"
}
}
]
},
"containsNull": true
},
"nullable": true,
"metadata": {
"delta.columnMapping.id": 4,
"delta.columnMapping.physicalName": "col-5f422f40-de70-45b2-88ab-1d5c90e94db1"
}
}
"#;
let field: StructField = serde_json::from_str(data).unwrap();

let col_id = field
.get_config_value(&ColumnMetadataKey::ColumnMappingId)
.unwrap();
assert!(matches!(col_id, MetadataValue::Number(num) if *num == 4));
let physical_name = field
.get_config_value(&ColumnMetadataKey::ColumnMappingPhysicalName)
.unwrap();
assert!(
matches!(physical_name, MetadataValue::String(name) if *name == "col-5f422f40-de70-45b2-88ab-1d5c90e94db1")
);
}

#[test]
fn test_read_schemas() {
let file = std::fs::File::open("./tests/serde/schema.json").unwrap();
let schema: Result<StructType, _> = serde_json::from_reader(file);
assert!(schema.is_ok());

let file = std::fs::File::open("./tests/serde/checkpoint_schema.json").unwrap();
let schema: Result<StructType, _> = serde_json::from_reader(file);
assert!(schema.is_ok())
}

#[test]
fn test_get_invariants() {
let schema: StructType = serde_json::from_value(json!({
Expand Down

0 comments on commit cd589f9

Please sign in to comment.