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

fix: properly decode percent-encoded file paths coming from parquet checkpoints #1970

Merged
merged 2 commits into from
Dec 18, 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
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.

Loading