zeroshade commented on code in PR #1745: URL: https://github.com/apache/iceberg-go/pull/1745#discussion_r3814540961
########## table/inspect_all_manifests.go: ########## @@ -0,0 +1,87 @@ +// 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. + +package table + +import ( + "context" + "errors" + "fmt" + + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/iceberg-go" +) + +// AllManifests returns every manifest referenced by every snapshot currently +// tracked by the table. A manifest referenced by multiple snapshots produces +// one row per reference, identified by reference_snapshot_id. +func (i InspectTable) AllManifests(ctx context.Context) (array.RecordReader, error) { + arrowSchema, err := SchemaToArrowSchema(AllManifestsSchema(), nil, true, false) + if err != nil { + return nil, fmt.Errorf("inspect all manifests: build arrow schema: %w", err) + } + + bldr := array.NewRecordBuilder(i.alloc, arrowSchema) Review Comment: This builder remains live across every retained snapshot, so memory grows with the complete set of manifest references (including repeated shared manifests, partition summaries, and key metadata). Because `AllManifests` returns a `RecordReader`, this should use an iterator-backed reader with a bounded builder rather than accumulating the entire history before returning. ########## table/inspect_all_manifests.go: ########## @@ -0,0 +1,87 @@ +// 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. + +package table + +import ( + "context" + "errors" + "fmt" + + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/iceberg-go" +) + +// AllManifests returns every manifest referenced by every snapshot currently +// tracked by the table. A manifest referenced by multiple snapshots produces +// one row per reference, identified by reference_snapshot_id. +func (i InspectTable) AllManifests(ctx context.Context) (array.RecordReader, error) { + arrowSchema, err := SchemaToArrowSchema(AllManifestsSchema(), nil, true, false) + if err != nil { + return nil, fmt.Errorf("inspect all manifests: build arrow schema: %w", err) + } + + bldr := array.NewRecordBuilder(i.alloc, arrowSchema) + defer bldr.Release() + + snapshots := i.tbl.metadata.Snapshots() + if len(snapshots) > 0 { + if i.tbl.fsF == nil { + return nil, errors.New("inspect all manifests: table file IO is not configured") + } + fs, err := i.tbl.fsF(ctx) + if err != nil { + return nil, fmt.Errorf("inspect all manifests: %w", err) + } + + for _, snapshot := range snapshots { + if err := ctx.Err(); err != nil { + return nil, err + } + manifests, err := snapshot.Manifests(fs) + if err != nil { + return nil, fmt.Errorf("inspect all manifests: read snapshot %d manifests: %w", + snapshot.SnapshotID, err) + } + referenceSnapshotID := snapshot.SnapshotID + if err := i.appendManifestRows(ctx, bldr, manifests, &referenceSnapshotID); err != nil { + return nil, fmt.Errorf("inspect all manifests: snapshot %d: %w", snapshot.SnapshotID, err) + } + } + } + + rr, err := singleBatchReader(arrowSchema, bldr) Review Comment: Returning a single batch here means callers receive no rows until every snapshot manifest list has been read and every row has been materialized, and they cannot stop early. Please emit fixed-size batches from `ReaderFromIter` while traversing snapshots, retaining at most the current manifest list plus one batch. A test with more rows than the batch limit should assert that multiple batches are produced. -- 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]
