rambleraptor commented on code in PR #1283:
URL: https://github.com/apache/iceberg-go/pull/1283#discussion_r3531767195


##########
table/rewrite_manifests.go:
##########
@@ -0,0 +1,368 @@
+// 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"
+       "fmt"
+       "slices"
+       "strconv"
+
+       "github.com/apache/iceberg-go"
+       iceio "github.com/apache/iceberg-go/io"
+)
+
+// Snapshot summary keys for a manifest rewrite.
+const (
+       manifestsCreatedKey  = "manifests-created"
+       manifestsReplacedKey = "manifests-replaced"
+       manifestsKeptKey     = "manifests-kept"
+       entriesProcessedKey  = "entries-processed"
+)
+
+// NoOpReason explains why a rewrite changed nothing. It lets callers tell a
+// table with no current snapshot apart from one whose manifests are already
+// optimal, which would otherwise both surface as an empty result.
+type NoOpReason string
+
+const (
+       // NoOpNone means the rewrite produced changes (not a no-op).
+       NoOpNone NoOpReason = ""
+       // NoOpNoSnapshot means the table had no current snapshot to rewrite.
+       NoOpNoSnapshot NoOpReason = "no current snapshot"
+       // NoOpAlreadyOptimal means the eligible manifests were already optimal.
+       NoOpAlreadyOptimal NoOpReason = "manifests already optimal"
+)
+
+// RewriteManifestsResult reports the manifests changed by a rewrite.
+type RewriteManifestsResult struct {
+       // RewrittenManifests are the old manifests that were replaced.
+       RewrittenManifests []iceberg.ManifestFile
+       // AddedManifests are the new manifests written in their place.
+       AddedManifests []iceberg.ManifestFile
+       // NoOpReason is set when the rewrite changed nothing, distinguishing a
+       // missing snapshot from an already-optimal layout. Empty otherwise.
+       NoOpReason NoOpReason
+}
+
+// IsNoOp reports whether the rewrite changed nothing. Callers should skip the
+// commit in that case rather than staging an empty REPLACE snapshot.
+func (r *RewriteManifestsResult) IsNoOp() bool {
+       return len(r.AddedManifests) == 0 && len(r.RewrittenManifests) == 0
+}
+
+type rewriteManifestsCfg struct {
+       targetSizeBytes int64
+       specID          *int
+       predicate       func(iceberg.ManifestFile) bool
+}
+
+// RewriteManifestsOpt configures [Transaction.RewriteManifests].
+type RewriteManifestsOpt func(*rewriteManifestsCfg)
+
+// WithManifestTargetSize overrides the target manifest size in bytes.
+// The default comes from the commit.manifest.target-size-bytes property.
+func WithManifestTargetSize(size int64) RewriteManifestsOpt {
+       return func(c *rewriteManifestsCfg) {
+               if size > 0 {
+                       c.targetSizeBytes = size

Review Comment:
   Yep, great call. I ended up putting this in a doc, since I didn't want to 
change the interface to include an error.



-- 
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]

Reply via email to