Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save operational params in the same way with delta io #1054

Merged
merged 3 commits into from
Jan 17, 2023
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
18 changes: 17 additions & 1 deletion rust/src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,25 @@ impl DeltaOperation {
);

if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(self) {
let all_operation_fields = map.values().next().unwrap().as_object().unwrap();
let converted_operation_fields: Map<String, Value> = all_operation_fields
.iter()
.filter(|item| !item.1.is_null())
.map(|(k, v)| {
(
k.clone(),
serde_json::Value::String(if v.is_string() {
String::from(v.as_str().unwrap())
} else {
v.to_string()
}),
)
})
.collect();

commit_info.insert(
"operationParameters".to_string(),
map.values().next().unwrap().clone(),
serde_json::Value::Object(converted_operation_fields),
);
};

Expand Down
2 changes: 1 addition & 1 deletion rust/tests/command_optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ async fn test_commit_info() -> Result<(), Box<dyn Error>> {
assert_eq!(last_commit["readVersion"], json!(version));
assert_eq!(
last_commit["operationParameters"]["targetSize"],
json!(2_000_000)
json!("2000000")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to see a test for partitionValues. Could you add that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, could you please clarify your request? I ask because "partitionValues" is not part of the commit info and operating params that have been changed in this PR.
Perhaps you want to check that "partitionBy" as part of the operating params is built correctly?

If you want exactly "partitionValues", I can figure out how to check that. But it looks like it should be in a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. I meant "partitionBy".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added separated unit test, because the most of commit info sections doesn't pass operation info. So they doesn't contains operational parameters which I can use to check.

);
// TODO: Requires a string representation for PartitionFilter
assert_eq!(last_commit["operationParameters"]["predicate"], Value::Null);
Expand Down
40 changes: 40 additions & 0 deletions rust/tests/commit_info_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#[allow(dead_code)]
mod fs_common;

use deltalake::action::{Action, DeltaOperation, SaveMode};

use serde_json::{json, Value};
use std::error::Error;

#[tokio::test]
async fn test_operational_parameters() -> Result<(), Box<dyn Error>> {
let path = "./tests/data/operational_parameters";
let mut table = fs_common::create_table(path, None).await;

let add = fs_common::add(0);

let operation = DeltaOperation::Write {
mode: SaveMode::Append,
partition_by: Some(vec!["some_partition".to_string()]),
predicate: None,
};

let mut tx = table.create_transaction(None);
let actions = vec![Action::add(add.clone())];
tx.add_actions(actions);
tx.commit(Some(operation), None).await.unwrap();

let commit_info = table.history(None).await?;
let last_commit = &commit_info[commit_info.len() - 1];

assert_eq!(last_commit["operationParameters"]["mode"], json!("Append"));

assert_eq!(
last_commit["operationParameters"]["partitionBy"],
json!("[\"some_partition\"]")
);

assert_eq!(last_commit["operationParameters"]["predicate"], Value::Null);

Ok(())
}