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

improve err msg on use of non-partitioned column #1221

Merged
merged 6 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions python/tests/test_table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def test_get_files_partitioned_table():
dt.files(partition_filters)
assert (
str(exception.value)
== 'Invalid partition filter found: [PartitionFilter { key: "unknown", value:'
' Equal("3") }].'
== 'Tried to filter partitions on column "unknown", but that column'
" is not partitioned."
)


Expand Down
7 changes: 7 additions & 0 deletions rust/src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ pub enum DeltaTableError {
/// The invalid partition filter used.
partition_filter: String,
},
/// Error returned when a partition filter uses a non-partitioned column
/// column.
#[error("Tried to filter partitions on column {}, but that column is not partitioned.", .column)]
ColumnNotPartitioned {
/// The column used in the partition filter that is not partitioned
column: String,
},
/// Error returned when a line from log record is invalid.
#[error("Failed to read line from log record")]
Io {
Expand Down
15 changes: 8 additions & 7 deletions rust/src/table_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,14 @@ impl DeltaTableState {
filters: &'a [PartitionFilter<'a, &'a str>],
) -> Result<impl Iterator<Item = &'a Add> + '_, DeltaTableError> {
let current_metadata = self.current_metadata().ok_or(DeltaTableError::NoMetadata)?;
if !filters
.iter()
.all(|f| current_metadata.partition_columns.contains(&f.key.into()))
{
return Err(DeltaTableError::InvalidPartitionFilter {
partition_filter: format!("{filters:?}"),
});

for f in filters {
if !current_metadata.partition_columns.contains(&f.key.into()) {
let column = f.key.to_string();
return Err(DeltaTableError::ColumnNotPartitioned {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick, the original implementation returns all columns that aren't partitioned, but this implementation does an early return, which results in a different behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @houqp, good point! I tried to restore to the original behavior in the latest commit

column: format!("{column:?}"),
});
}
}

let partition_col_data_types: HashMap<&str, &SchemaDataType> = current_metadata
Expand Down