Skip to content

Commit

Permalink
Modify get_files_by_partitions to use partition values instead of fil…
Browse files Browse the repository at this point in the history
…e paths. (#362)
  • Loading branch information
zijie0 authored Aug 8, 2021
1 parent b1925f2 commit 61e2941
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
17 changes: 3 additions & 14 deletions rust/src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,26 +765,15 @@ impl DeltaTable {
&self,
filters: &[PartitionFilter<&str>],
) -> Result<Vec<String>, DeltaTableError> {
let partitions_number = match &self
.state
.current_metadata
.as_ref()
.ok_or(DeltaTableError::NoMetadata)?
.partition_columns
{
partitions if !partitions.is_empty() => partitions.len(),
_ => return Err(DeltaTableError::LoadPartitions),
};
let separator = "/";
let files = self
.state
.files
.iter()
.filter(|add| {
let partitions = add
.path
.splitn(partitions_number + 1, separator)
.filter_map(|p: &str| DeltaTablePartition::try_from(p).ok())
.partition_values
.iter()
.map(|p| DeltaTablePartition::from_partition_value(p, ""))
.collect::<Vec<DeltaTablePartition>>();
filters
.iter()
Expand Down
15 changes: 15 additions & 0 deletions rust/src/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ impl<'a> TryFrom<&'a str> for DeltaTablePartition<'a> {
}
}
}

impl<'a> DeltaTablePartition<'a> {
/// Try to create a DeltaTable partition from a partition value kv pair.
pub fn from_partition_value(
partition_value: (&'a String, &'a Option<String>),
default_for_null: &'a str,
) -> Self {
let (k, v) = partition_value;
let v = match v {
Some(s) => s,
None => default_for_null,
};
DeltaTablePartition { key: k, value: v }
}
}
2 changes: 1 addition & 1 deletion rust/tests/read_delta_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ async fn read_delta_8_0_table_with_null_partition() {

let filters = vec![deltalake::PartitionFilter {
key: "k",
value: deltalake::PartitionValue::Equal("__HIVE_DEFAULT_PARTITION__"),
value: deltalake::PartitionValue::Equal(""),
}];
assert_eq!(
table.get_files_by_partitions(&filters).unwrap(),
Expand Down

0 comments on commit 61e2941

Please sign in to comment.