-
Notifications
You must be signed in to change notification settings - Fork 189
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
Split metadata tables into separate modules #872
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use super::{ManifestsTable, SnapshotsTable}; | ||
use crate::table::Table; | ||
|
||
/// Metadata table is used to inspect a table's history, snapshots, and other metadata as a table. | ||
/// | ||
/// References: | ||
/// - <https://github.com/apache/iceberg/blob/ac865e334e143dfd9e33011d8cf710b46d91f1e5/core/src/main/java/org/apache/iceberg/MetadataTableType.java#L23-L39> | ||
/// - <https://iceberg.apache.org/docs/latest/spark-queries/#querying-with-sql> | ||
/// - <https://py.iceberg.apache.org/api/#inspecting-tables> | ||
#[derive(Debug)] | ||
pub struct MetadataTable(Table); | ||
|
||
impl MetadataTable { | ||
/// Creates a new metadata scan. | ||
pub fn new(table: Table) -> Self { | ||
Self(table) | ||
} | ||
|
||
/// Get the snapshots table. | ||
pub fn snapshots(&self) -> SnapshotsTable { | ||
SnapshotsTable::new(&self.0) | ||
} | ||
|
||
/// Get the manifests table. | ||
pub fn manifests(&self) -> ManifestsTable { | ||
ManifestsTable::new(&self.0) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use arrow_array::RecordBatch; | ||
use expect_test::Expect; | ||
use itertools::Itertools; | ||
|
||
/// Snapshot testing to check the resulting record batch. | ||
/// | ||
/// - `expected_schema/data`: put `expect![[""]]` as a placeholder, | ||
/// and then run test with `UPDATE_EXPECT=1 cargo test` to automatically update the result, | ||
/// or use rust-analyzer (see [video](https://github.com/rust-analyzer/expect-test)). | ||
/// Check the doc of [`expect_test`] for more details. | ||
/// - `ignore_check_columns`: Some columns are not stable, so we can skip them. | ||
/// - `sort_column`: The order of the data might be non-deterministic, so we can sort it by a column. | ||
pub fn check_record_batch( | ||
record_batch: RecordBatch, | ||
expected_schema: Expect, | ||
expected_data: Expect, | ||
ignore_check_columns: &[&str], | ||
sort_column: Option<&str>, | ||
) { | ||
let mut columns = record_batch.columns().to_vec(); | ||
if let Some(sort_column) = sort_column { | ||
let column = record_batch.column_by_name(sort_column).unwrap(); | ||
let indices = arrow_ord::sort::sort_to_indices(column, None, None).unwrap(); | ||
columns = columns | ||
.iter() | ||
.map(|column| arrow_select::take::take(column.as_ref(), &indices, None).unwrap()) | ||
.collect_vec(); | ||
} | ||
|
||
expected_schema.assert_eq(&format!( | ||
"{}", | ||
record_batch.schema().fields().iter().format(",\n") | ||
)); | ||
expected_data.assert_eq(&format!( | ||
"{}", | ||
record_batch | ||
.schema() | ||
.fields() | ||
.iter() | ||
.zip_eq(columns) | ||
.map(|(field, column)| { | ||
if ignore_check_columns.contains(&field.name().as_str()) { | ||
format!("{}: (skipped)", field.name()) | ||
} else { | ||
format!("{}: {:?}", field.name(), column) | ||
} | ||
}) | ||
.format(",\n") | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Metadata table APIs. | ||
|
||
mod manifests; | ||
mod metadata_table; | ||
mod snapshots; | ||
|
||
pub use manifests::ManifestsTable; | ||
pub use metadata_table::*; | ||
pub use snapshots::SnapshotsTable; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why we need this data struct here. It seems just a wrapper to provide more api, while just like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @Xuanwo @sdd @Fokko What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I intend to make the API exposed at
Table
more organized. For example, users will have:instead of:
While I believe we could use better API names, such as
table.inspect().snapshots()
, the overall structure looks good to me and aligns better with other implementations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
metadata_table
toinspect
rename is here: #881