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


##########
table/rewrite_manifests_test.go:
##########
@@ -0,0 +1,833 @@
+// 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_test
+
+import (
+       "context"
+       "fmt"
+       "path/filepath"
+       "strconv"
+       "strings"
+       "sync"
+       "sync/atomic"
+       "testing"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/apache/arrow-go/v18/parquet/pqarrow"
+       "github.com/apache/iceberg-go"
+       iceio "github.com/apache/iceberg-go/io"
+       "github.com/apache/iceberg-go/table"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+// activeFiles sums the added + existing data files across manifests. It 
mirrors
+// the production accounting in manifestActiveFiles: a manifest that reports a
+// negative (unknown) count fails the test rather than being silently folded 
in,
+// so a count we can't trust never masquerades as a valid total.
+func activeFiles(t *testing.T, manifests []iceberg.ManifestFile) int {
+       t.Helper()
+       var n int
+       for _, m := range manifests {
+               added, existing := m.AddedDataFiles(), m.ExistingDataFiles()
+               require.False(t, added < 0 || existing < 0,
+                       "manifest %s reports an unknown data-file count", 
m.FilePath())
+               n += int(added) + int(existing)
+       }
+
+       return n
+}
+
+// rewriteArrowSchema is the single-column schema used by the rewrite tests.
+var rewriteArrowSchema = arrow.NewSchema([]arrow.Field{
+       {Name: "id", Type: arrow.PrimitiveTypes.Int32, Nullable: false},
+}, nil)
+
+// writeOneRowParquet writes a one-row Parquet file at path.
+func writeOneRowParquet(t *testing.T, fs iceio.WriteFileIO, path string) {
+       t.Helper()
+
+       bldr := array.NewInt32Builder(memory.DefaultAllocator)
+       defer bldr.Release()
+
+       bldr.AppendValues([]int32{1}, nil)
+       col := bldr.NewArray()
+       defer col.Release()
+
+       rec := array.NewRecordBatch(rewriteArrowSchema, []arrow.Array{col}, 1)
+       defer rec.Release()
+
+       arrTbl := array.NewTableFromRecords(rewriteArrowSchema, 
[]arrow.RecordBatch{rec})
+       defer arrTbl.Release()
+
+       fo, err := fs.Create(path)
+       require.NoError(t, err)
+       require.NoError(t, pqarrow.WriteTable(arrTbl, fo, arrTbl.NumRows(),
+               nil, pqarrow.DefaultWriterProps()))
+}
+
+func rewriteSchema() *iceberg.Schema {
+       return iceberg.NewSchema(1,
+               iceberg.NestedField{ID: 1, Name: "id", Type: 
iceberg.PrimitiveTypes.Int32, Required: true},
+       )
+}
+
+// appendSeparateManifests performs n single-row appends, each in its own
+// commit, leaving n separate data manifests behind (merge must be disabled on
+// the table). It returns the table after the final commit.
+func appendSeparateManifests(t *testing.T, ctx context.Context, tbl 
*table.Table, fs iceio.WriteFileIO, dir, prefix string, n int) *table.Table {
+       t.Helper()
+       var err error
+       for i := range n {
+               filePath := fmt.Sprintf("%s/%s-%d.parquet", dir, prefix, i)
+               writeOneRowParquet(t, fs, filePath)
+
+               txn := tbl.NewTransaction()
+               require.NoError(t, txn.AddFiles(ctx, []string{filePath}, nil, 
false))
+               tbl, err = txn.Commit(ctx)
+               require.NoError(t, err)
+       }
+
+       return tbl
+}
+
+// TestRewriteManifests merges several small data manifests into one without
+// changing the data files they reference.
+func TestRewriteManifests(t *testing.T) {

Review Comment:
   Added the test.



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