You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "c-thiel (via GitHub)" <gi...@apache.org> on 2024/09/22 14:11:20 UTC

[PR] Feat: Add NamespaceIdent.parent() [iceberg-rust]

c-thiel opened a new pull request, #641:
URL: https://github.com/apache/iceberg-rust/pull/641

   Helpful when working with hierarchical namespaces, as `from_vec` is fallible.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: Add NamespaceIdent.parent() [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #641:
URL: https://github.com/apache/iceberg-rust/pull/641


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: Add NamespaceIdent.parent() [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #641:
URL: https://github.com/apache/iceberg-rust/pull/641#discussion_r1772486755


##########
crates/iceberg/src/catalog/mod.rs:
##########
@@ -133,6 +133,16 @@ impl NamespaceIdent {
     pub fn inner(self) -> Vec<String> {
         self.0
     }
+
+    /// Get the parent of this namespace.
+    /// Returns None if this namespace only has a single element and thus has no parent.
+    pub fn parent(&self) -> Option<Self> {
+        if self.0.len() <= 1 {
+            None
+        } else {
+            Some(Self(self.0[..self.0.len() - 1].to_vec()))
+        }
+    }

Review Comment:
   You are right. I misremembered this API.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: Add NamespaceIdent.parent() [iceberg-rust]

Posted by "c-thiel (via GitHub)" <gi...@apache.org>.
c-thiel commented on code in PR #641:
URL: https://github.com/apache/iceberg-rust/pull/641#discussion_r1772000307


##########
crates/iceberg/src/catalog/mod.rs:
##########
@@ -133,6 +133,16 @@ impl NamespaceIdent {
     pub fn inner(self) -> Vec<String> {
         self.0
     }
+
+    /// Get the parent of this namespace.
+    /// Returns None if this namespace only has a single element and thus has no parent.
+    pub fn parent(&self) -> Option<Self> {
+        if self.0.len() <= 1 {
+            None
+        } else {
+            Some(Self(self.0[..self.0.len() - 1].to_vec()))
+        }
+    }

Review Comment:
   It's not quite as elegant, as split_last() might still yield an empty parent. I switched to `split_last` in the latest commit.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: Add NamespaceIdent.parent() [iceberg-rust]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #641:
URL: https://github.com/apache/iceberg-rust/pull/641#discussion_r1770894847


##########
crates/iceberg/src/catalog/mod.rs:
##########
@@ -133,6 +133,16 @@ impl NamespaceIdent {
     pub fn inner(self) -> Vec<String> {
         self.0
     }
+
+    /// Get the parent of this namespace.
+    /// Returns None if this namespace only has a single element and thus has no parent.
+    pub fn parent(&self) -> Option<Self> {
+        if self.0.len() <= 1 {
+            None
+        } else {
+            Some(Self(self.0[..self.0.len() - 1].to_vec()))
+        }
+    }

Review Comment:
   How about using [split_last](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last)? So that we have:
   
   ```rust
   pub fn parent(&self) -> Option<Self> {
       let (parent, _) = self.0.split_last()?;
       Some(Self(parent.to_vec()))
   }
   ```



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org