tanmayrauth commented on code in PR #1113:
URL: https://github.com/apache/iceberg-go/pull/1113#discussion_r3291926236
##########
table/arrow_utils.go:
##########
@@ -1704,3 +1714,43 @@ func positionDeleteRecordsToDataFiles(ctx
context.Context, rootLocation string,
return partitionWriter.Write(ctx, workers)
}
+
+func positionDeleteRecordsToDataFilesDV(ctx context.Context, rootLocation
string, args recordWritingArgs) iter.Seq2[iceberg.DataFile, error] {
+ return func(yield func(iceberg.DataFile, error) bool) {
+ writer := dv.NewDVWriter(args.fs)
+
+ for batch, err := range args.itr {
+ if err != nil {
+ yield(nil, err)
+
+ return
+ }
+
+ filePaths := batch.Column(0).(*array.String)
+ positions := batch.Column(1).(*array.Int64)
+
+ for i := range batch.NumRows() {
+ writer.Add(filePaths.Value(int(i)),
[]int64{positions.Value(int(i))})
+ }
+ }
+
+ u := uuid.Must(uuid.NewRandom())
+ if args.writeUUID != nil {
+ u = *args.writeUUID
+ }
Review Comment:
Switched the DV path to the cleaner form used by the Parquet path (only
generate a UUID when args.writeUUID is nil) and moved it below the empty-input
early-return so we no longer generate a UUID when there's nothing to flush.
##########
table/dv_write_path_test.go:
##########
@@ -0,0 +1,123 @@
+// 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"
+ "testing"
+
+ "github.com/apache/arrow-go/v18/arrow"
+ "github.com/apache/iceberg-go"
+ iceio "github.com/apache/iceberg-go/io"
+ "github.com/apache/iceberg-go/table/dv"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestDVWritePathProducesReadableOutput(t *testing.T) {
+ mb := newPositionDeleteUnpartitionedMetadata(t, 3)
+ fs := iceio.NewMemFS()
+
+ batch := mustLoadRecordBatchFromJSON(PositionalDeleteArrowSchema, `[
+ {"file_path": "s3://bucket/data/file-001.parquet", "pos": 1},
+ {"file_path": "s3://bucket/data/file-001.parquet", "pos": 3},
+ {"file_path": "s3://bucket/data/file-001.parquet", "pos": 5},
+ {"file_path": "s3://bucket/data/file-002.parquet", "pos": 0},
+ {"file_path": "s3://bucket/data/file-002.parquet", "pos": 10}
+ ]`)
+ itr := func(yield func(arrow.RecordBatch, error) bool) {
+ batch.Retain()
+ yield(batch, nil)
+ }
+
+ seq := positionDeleteRecordsToDataFiles(context.Background(),
"mem://test", mb, nil,
+ recordWritingArgs{
+ sc: PositionalDeleteArrowSchema,
+ itr: itr,
+ fs: fs,
+ })
+
+ var dataFiles []iceberg.DataFile
+ for df, err := range seq {
+ require.NoError(t, err)
+ dataFiles = append(dataFiles, df)
+ }
+
+ require.Len(t, dataFiles, 2)
+
+ df1 := dataFiles[0]
+ assert.Equal(t, iceberg.PuffinFile, df1.FileFormat())
+ assert.Equal(t, int64(3), df1.Count())
+ assert.Equal(t, "s3://bucket/data/file-001.parquet",
*df1.ReferencedDataFile())
+ assert.NotNil(t, df1.ContentOffset())
+ assert.NotNil(t, df1.ContentSizeInBytes())
+
+ df2 := dataFiles[1]
+ assert.Equal(t, iceberg.PuffinFile, df2.FileFormat())
+ assert.Equal(t, int64(2), df2.Count())
+ assert.Equal(t, "s3://bucket/data/file-002.parquet",
*df2.ReferencedDataFile())
+
+ bm1, err := dv.ReadDV(fs, df1)
+ require.NoError(t, err)
+ assert.Equal(t, int64(3), bm1.Cardinality())
+ assert.True(t, bm1.Contains(1))
+ assert.True(t, bm1.Contains(3))
+ assert.True(t, bm1.Contains(5))
+ assert.False(t, bm1.Contains(2))
+
+ bm2, err := dv.ReadDV(fs, df2)
+ require.NoError(t, err)
+ assert.Equal(t, int64(2), bm2.Cardinality())
+ assert.True(t, bm2.Contains(0))
+ assert.True(t, bm2.Contains(10))
+}
+
+func TestDVWritePathV2FallsBackToPosition(t *testing.T) {
+ mb := newPositionDeleteUnpartitionedMetadata(t, 2)
+
+ emptyItr := func(yield func(arrow.RecordBatch, error) bool) {}
+
+ seq := positionDeleteRecordsToDataFiles(context.Background(),
t.TempDir(), mb, nil,
+ recordWritingArgs{
+ sc: PositionalDeleteArrowSchema,
+ itr: emptyItr,
+ fs: iceio.LocalFS{},
+ })
Review Comment:
You're right, the empty iterator made it a no-op assertion. Reworked it: the
v2 fallback test now feeds a non-empty batch and asserts that the first
returned DataFile's format is Parquet. Also added a v3-partitioned fallback
test with the same Parquet assertion. The explicit-property test went away with
comment #2.
--
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]