Skip to content

Commit

Permalink
fix: make sure percent-encoded file paths are properly decoded when c…
Browse files Browse the repository at this point in the history
…oming from parquet checkpoints, to prevent tombstone and file paths mismatch (e.g. file path is read from checkpoint while tombstone path is read from JSON)
  • Loading branch information
Igor Borodin authored and rtyler committed Dec 18, 2023
1 parent be75827 commit 763d39e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 99 deletions.
2 changes: 1 addition & 1 deletion crates/deltalake-core/src/kernel/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};

pub(crate) mod schemas;
mod serde_path;
pub(crate) mod serde_path;
pub(crate) mod types;

pub use types::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/deltalake-core/src/kernel/actions/serde_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn encode_path(path: &str) -> String {
percent_encode(path.as_bytes(), INVALID).to_string()
}

fn decode_path(path: &str) -> Result<String, Utf8Error> {
pub fn decode_path(path: &str) -> Result<String, Utf8Error> {
Ok(percent_decode_str(path).decode_utf8()?.to_string())
}

Expand Down
7 changes: 7 additions & 0 deletions crates/deltalake-core/src/protocol/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ impl From<CheckpointError> for ProtocolError {
}
}

use core::str::Utf8Error;
impl From<Utf8Error> for ProtocolError {
fn from(value: Utf8Error) -> Self {
Self::Generic(value.to_string())
}
}

/// The record batch size for checkpoint parquet file
pub const CHECKPOINT_RECORD_BATCH_SIZE: usize = 5000;

Expand Down
23 changes: 15 additions & 8 deletions crates/deltalake-core/src/protocol/parquet_read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use num_traits::cast::ToPrimitive;
use parquet::record::{Field, ListAccessor, MapAccessor, RowAccessor};
use serde_json::json;

use crate::kernel::serde_path::decode_path;
use crate::kernel::{
Action, Add, AddCDCFile, DeletionVectorDescriptor, Metadata, Protocol, Remove, StorageType, Txn,
};
Expand Down Expand Up @@ -119,10 +120,13 @@ impl Add {
for (i, (name, _)) in record.get_column_iter().enumerate() {
match name.as_str() {
"path" => {
re.path = record
.get_string(i)
.map_err(|_| gen_action_type_error("add", "path", "string"))?
.clone();
re.path = decode_path(
record
.get_string(i)
.map_err(|_| gen_action_type_error("add", "path", "string"))?
.clone()
.as_str(),
)?;
}
"size" => {
re.size = record
Expand Down Expand Up @@ -515,10 +519,13 @@ impl Remove {
for (i, (name, _)) in record.get_column_iter().enumerate() {
match name.as_str() {
"path" => {
re.path = record
.get_string(i)
.map_err(|_| gen_action_type_error("remove", "path", "string"))?
.clone();
re.path = decode_path(
record
.get_string(i)
.map_err(|_| gen_action_type_error("remove", "path", "string"))?
.clone()
.as_str(),
)?;
}
"dataChange" => {
re.data_change = record
Expand Down
89 changes: 0 additions & 89 deletions crates/deltalake-core/src/protocol/serde_path.rs

This file was deleted.

0 comments on commit 763d39e

Please sign in to comment.