blackmwk commented on code in PR #1876:
URL: https://github.com/apache/iceberg-rust/pull/1876#discussion_r2756694810
##########
crates/iceberg/src/spec/table_metadata.rs:
##########
@@ -468,9 +483,44 @@ impl TableMetadata {
file_io: &FileIO,
metadata_location: impl AsRef<str>,
Review Comment:
I have added comments here:
https://github.com/apache/iceberg-rust/pull/1876/changes#r2756683326
I think with this approach we will be able provide an idiomatic api.
##########
crates/iceberg/src/catalog/metadata_location.rs:
##########
@@ -15,38 +15,100 @@
// specific language governing permissions and limitations
// under the License.
+use std::collections::HashMap;
use std::fmt::Display;
use std::str::FromStr;
use uuid::Uuid;
+use crate::compression::CompressionCodec;
+use crate::spec::{TableMetadata, parse_metadata_file_compression};
use crate::{Error, ErrorKind, Result};
/// Helper for parsing a location of the format:
`<location>/metadata/<version>-<uuid>.metadata.json`
+/// or with compression:
`<location>/metadata/<version>-<uuid>.gz.metadata.json`
#[derive(Clone, Debug, PartialEq)]
pub struct MetadataLocation {
table_location: String,
version: i32,
id: Uuid,
+ compression_suffix: Option<String>,
}
impl MetadataLocation {
+ /// Determines the compression suffix from table properties.
+ fn compression_suffix_from_properties(
+ properties: &HashMap<String, String>,
+ ) -> Result<Option<String>> {
+ let codec = parse_metadata_file_compression(properties)?;
+
+ Ok(if codec.is_none() {
+ None
+ } else {
+ Some(codec.suffix()?.to_string())
+ })
+ }
+
/// Creates a completely new metadata location starting at version 0.
- /// Only used for creating a new table. For updates, see
`with_next_version`.
+ /// Only used for creating a new table. For updates, see `next_version`.
+ #[deprecated(
+ since = "0.8.0",
+ note = "Use new_with_metadata instead to properly handle compression
settings"
+ )]
pub fn new_with_table_location(table_location: impl ToString) -> Self {
Self {
table_location: table_location.to_string(),
version: 0,
id: Uuid::new_v4(),
+ compression_suffix: None,
+ }
+ }
+
+ /// Creates a completely new metadata location starting at version 0,
+ /// with compression settings from the table metadata.
+ /// Only used for creating a new table. For updates, see `next_version`.
+ pub fn new_with_metadata(table_location: impl ToString, metadata:
&TableMetadata) -> Self {
+ Self {
+ table_location: table_location.to_string(),
+ version: 0,
+ id: Uuid::new_v4(),
+ // This will go away
https://github.com/apache/iceberg-rust/issues/2028 is resolved, so for now
+ // we use a default value.
+ compression_suffix:
Self::compression_suffix_from_properties(metadata.properties())
+ .unwrap_or(None),
}
}
/// Creates a new metadata location for an updated metadata file.
+ /// Uses compression settings from the new metadata.
+ pub fn next_version(
Review Comment:
I think I got your point. Then a more idiomatic approach would be adding a
new member function as following:
```
pub fn with_new_metadata(&self, metadata: &TableMetadata) -> Self {
...
}
```
And the user is expected to call as following:
```
let meta_loc: MetadataLocation = ...;
let new_meta_loc = meta_loc.with_next_version().with_new_metadata();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]