Skip to content

Commit

Permalink
Expose length of iterators via ExactSizeIterator (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-thiel authored Nov 11, 2024
1 parent 40e3ea4 commit 213f84e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl Schema {

/// Returns [`identifier_field_ids`].
#[inline]
pub fn identifier_field_ids(&self) -> impl Iterator<Item = i32> + '_ {
pub fn identifier_field_ids(&self) -> impl ExactSizeIterator<Item = i32> + '_ {
self.identifier_field_ids.iter().copied()
}

Expand Down
10 changes: 6 additions & 4 deletions crates/iceberg/src/spec/table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl TableMetadata {

/// Returns schemas
#[inline]
pub fn schemas_iter(&self) -> impl Iterator<Item = &SchemaRef> {
pub fn schemas_iter(&self) -> impl ExactSizeIterator<Item = &SchemaRef> {
self.schemas.values()
}

Expand All @@ -228,7 +228,9 @@ impl TableMetadata {

/// Returns all partition specs.
#[inline]
pub fn partition_specs_iter(&self) -> impl Iterator<Item = &SchemalessPartitionSpecRef> {
pub fn partition_specs_iter(
&self,
) -> impl ExactSizeIterator<Item = &SchemalessPartitionSpecRef> {
self.partition_specs.values()
}

Expand All @@ -252,7 +254,7 @@ impl TableMetadata {

/// Returns all snapshots
#[inline]
pub fn snapshots(&self) -> impl Iterator<Item = &SnapshotRef> {
pub fn snapshots(&self) -> impl ExactSizeIterator<Item = &SnapshotRef> {
self.snapshots.values()
}

Expand Down Expand Up @@ -301,7 +303,7 @@ impl TableMetadata {

/// Return all sort orders.
#[inline]
pub fn sort_orders_iter(&self) -> impl Iterator<Item = &SortOrderRef> {
pub fn sort_orders_iter(&self) -> impl ExactSizeIterator<Item = &SortOrderRef> {
self.sort_orders.values()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iceberg/src/spec/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ impl Struct {
}

/// Create a iterator to read the field in order of field_value.
pub fn iter(&self) -> impl Iterator<Item = Option<&Literal>> {
pub fn iter(&self) -> impl ExactSizeIterator<Item = Option<&Literal>> {
self.null_bitmap.iter().zip(self.fields.iter()).map(
|(null, value)| {
if *null {
Expand Down
4 changes: 2 additions & 2 deletions crates/iceberg/src/spec/view_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ViewMetadata {

/// Returns all view versions.
#[inline]
pub fn versions(&self) -> impl Iterator<Item = &ViewVersionRef> {
pub fn versions(&self) -> impl ExactSizeIterator<Item = &ViewVersionRef> {
self.versions.values()
}

Expand All @@ -114,7 +114,7 @@ impl ViewMetadata {

/// Returns schemas
#[inline]
pub fn schemas_iter(&self) -> impl Iterator<Item = &SchemaRef> {
pub fn schemas_iter(&self) -> impl ExactSizeIterator<Item = &SchemaRef> {
self.schemas.values()
}

Expand Down

0 comments on commit 213f84e

Please sign in to comment.