in crates/paimon/src/spec/schema_change.rs [273:404]
fn test_schema_change_serialize_deserialize() {
let json_data = r#"
[
{
"setOption": {
"key": "snapshot.time-retained",
"value": "2h"
}
},
{
"removeOption": {
"key": "compaction.max.file-num"
}
},
{
"updateComment": {
"comment": "table.comment"
}
},
{
"addColumn": {
"fieldName": "col1",
"dataType": "INT",
"description": "col1_description",
"move": {
"fieldName": "col1_first",
"referencedFieldName": null,
"type": "FIRST"
}
}
},
{
"renameColumn": {
"fieldName": "col3",
"newName": "col3_new_name"
}
},
{
"dropColumn": {
"fieldName": "col1"
}
},
{
"updateColumnType": {
"fieldName": "col14",
"dataType": "DOUBLE"
}
},
{
"updateColumnPosition": {
"move": {
"fieldName": "col4_first",
"referencedFieldName": null,
"type": "FIRST"
}
}
},
{
"updateColumnNullability": {
"fieldName": [
"col5",
"f2"
],
"nullable": false
}
},
{
"updateColumnComment": {
"fieldNames": [
"col5",
"f1"
],
"newDescription": "col5 f1 field"
}
}
]"#;
let schema_changes: Vec<SchemaChange> =
serde_json::from_str(json_data).expect("Failed to deserialize SchemaChange.");
assert_eq!(
schema_changes,
vec![
SchemaChange::SetOption {
key: "snapshot.time-retained".to_string(),
value: "2h".to_string(),
},
SchemaChange::RemoveOption {
key: "compaction.max.file-num".to_string(),
},
SchemaChange::UpdateComment {
comment: Some("table.comment".to_string()),
},
SchemaChange::AddColumn {
field_name: "col1".to_string(),
data_type: DataType::Int(IntType::new()),
description: Some("col1_description".to_string()),
column_move: Some(ColumnMove {
field_name: "col1_first".to_string(),
referenced_field_name: None,
move_type: ColumnMoveType::FIRST,
}),
},
SchemaChange::RenameColumn {
field_name: "col3".to_string(),
new_name: "col3_new_name".to_string(),
},
SchemaChange::DropColumn {
field_name: "col1".to_string(),
},
SchemaChange::UpdateColumnType {
field_name: "col14".to_string(),
data_type: DataType::Double(DoubleType::new()),
},
SchemaChange::UpdateColumnPosition {
column_move: ColumnMove {
field_name: "col4_first".to_string(),
referenced_field_name: None,
move_type: ColumnMoveType::FIRST,
},
},
SchemaChange::UpdateColumnNullability {
field_name: vec!["col5".to_string(), "f2".to_string()],
nullable: false,
},
SchemaChange::UpdateColumnComment {
field_names: vec!["col5".to_string(), "f1".to_string()],
new_description: "col5 f1 field".to_string(),
},
]
);
}