deps: bump parquet-go to v0.33.0 (#13130)

* deps: bump parquet-go to v0.33.0

parquet-go v0.33.0 fixes several bugs that Iceberg compaction runs into:

- BOOLEAN columns that Arrow and parquet-mr write with data page v2 are
  RLE-encoded. v0.32.0 decoded such runs wrong (a run's value byte expanded
  bit by bit, runs taken as multiples of 8 values), so compaction rewrote the
  flags wrong, and it wrote its own runs of trues with the value byte 0xFF,
  which DuckDB refuses to read ("Payload value bigger than allowed")
  (parquet-go/parquet-go#617, fixed by parquet-go/parquet-go#620).
- A column chunk without a dictionary lists the level encoding RLE next to
  PLAIN. v0.32.0 took RLE as the column's encoding, so the schema derived from
  a non-dictionary INT32 or DATE file could not write ("RLE: cannot encode
  INT32 with invalid bit-width=0") and such files never compacted
  (parquet-go/parquet-go#603, fixed by parquet-go/parquet-go#611).
- The sorting writer dropped the row groups' geospatial statistics when a
  bin fit in its sort buffer, so a sorted rewrite of a geometry table wrote
  files without a geometry bound (parquet-go/parquet-go#627, fixed by parquet-go/parquet-go#693 and parquet-go/parquet-go#700).
- A null in a list of required values wrote no value and shifted the rest of
  the page (parquet-go/parquet-go#616, fixed by parquet-go/parquet-go#618); a short data page read leftover
  values from a pooled buffer instead of failing (parquet-go/parquet-go#624, fixed by
  parquet-go/parquet-go#731).
- A geometry or geography column declared without a CRS is now written
  without one rather than with OGC:CRS84 spelled out (parquet-go/parquet-go#628, fixed
  by parquet-go/parquet-go#688).

Changes that follow from the bump:

- A corrupt data page now fails with an error rather than a panic. The
  position and equality delete readers returned that error without the file
  name; they now name the file, as the data file merge already does.
- The default-CRS tests built their "spelled out" inputs with
  parquet.Geometry(""), which now writes no CRS; they declare OGC:CRS84
  explicitly. The footer rewrite in geometry_crs.go is still needed when an
  input spells the default out, since the output schema comes from an input.

Tests:

- compact_rle_boolean_test.go with four pyarrow fixtures: two files with
  v2-page RLE booleans (with nulls) read back and compacted with every flag
  kept, and two non-dictionary INT32/DATE files compacted with every value
  kept. All three tests fail on v0.32.0 (3005 of 6000 flags wrong; "no bins
  successfully compacted").
- TestCompactSortedGeometryBoundCoversEveryRow only checked a bound when
  there was one, so it passed with the statistics dropped. It now requires a
  geometry bound on the data file and geometry statistics in the footer; it
  fails on v0.32.0 and passes on v0.33.0.
- go vet and go test of every package that imports parquet-go
  (weed/admin/dash, weed/mq/logstore, weed/mq/schema, weed/query/engine,
  weed/worker/tasks/iceberg) pass; -race on weed/worker/tasks/iceberg and
  weed/mq/logstore passes; go build ./weed passes.

* iceberg: fail the Arrow fixture tests on a read error

Both row-reading loops ended on any error, so rows decoded next to an
error could still pass the value checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* iceberg: check each fixture row comes out of compaction exactly once

A row replaced by a copy of another kept the row count and passed the
value checks, which use the row's own id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-30 10:18:24 -08:00
1 parent 5017a07475
commit 347f1cf705
12 files changed
+367 -66

No files matched your search

+5 -5
View File
@@ -58,7 +58,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/k0kubun/pp v3.0.1+incompatible
github.com/karlseguin/ccache/v2 v2.0.8
github.com/klauspost/compress v1.20.3
github.com/klauspost/compress v1.20.5
github.com/klauspost/reedsolomon v1.14.2
github.com/kurin/blazer v0.5.3
github.com/linkedin/goavro/v2 v2.15.0
@@ -67,7 +67,7 @@ require (
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4
github.com/olivere/elastic/v7 v7.0.32
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/parquet-go/parquet-go v0.32.0
github.com/parquet-go/parquet-go v0.33.0
github.com/peterh/liner v1.2.3
github.com/pierrec/lz4/v4 v4.1.33
github.com/pkg/sftp v1.13.12
@@ -171,7 +171,7 @@ require (
github.com/abbot/go-http-auth v0.4.0 // indirect
github.com/adrg/xdg v0.5.3 // indirect
github.com/anchore/go-lzo v0.1.1 // indirect
github.com/andybalholm/brotli v1.2.8 // indirect
github.com/andybalholm/brotli v1.3.0 // indirect
github.com/andybalholm/cascadia v1.3.4 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/apache/thrift v0.25.0 // indirect
@@ -374,8 +374,8 @@ require (
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/oracle/oci-go-sdk/v65 v65.121.0 // indirect
github.com/panjf2000/ants/v2 v2.12.1 // indirect
github.com/parquet-go/bitpack v1.0.0 // indirect
github.com/parquet-go/jsonlite v1.0.0 // indirect
github.com/parquet-go/bitpack v1.1.1 // indirect
github.com/parquet-go/jsonlite v1.5.7 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
github.com/pengsrc/go-shared v0.2.1-0.20190131101655-1999055a4a14 // indirect
+10 -10
View File
@@ -142,8 +142,8 @@ github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e h1:4dAU9FXIyQktp
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/anchore/go-lzo v0.1.1 h1:IwL/fvkdtlIrYIXck6WxZ3nb8WjjHziYYmGxlooyOnM=
github.com/anchore/go-lzo v0.1.1/go.mod h1:3kLx0bve2oN1iDwgM1U5zGku1Tfbdb0No5qp1eL1fIk=
github.com/andybalholm/brotli v1.2.8 h1:H9F6r7RNwzSRsx/lytpIYkbjNFMt2yNBwsJ2+0gpx78=
github.com/andybalholm/brotli v1.2.8/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/andybalholm/brotli v1.3.0 h1:IdkhjSe/+34U+fP7FSR2Q6Poj1hnHUa2GoWmzXJd6qY=
github.com/andybalholm/brotli v1.3.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/andybalholm/cascadia v1.3.4 h1:vM2lgh0Vru9Vwyfm4cQqWP2HHMW0u0+2PAW7Q38Qufg=
github.com/andybalholm/cascadia v1.3.4/go.mod h1:BLRmbRjpEtNKieZOCCvYj4RqN+KRA41GBe/5O+G93kM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
@@ -782,8 +782,8 @@ github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXw
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4=
github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/compress v1.20.5 h1:rJj5VjH4xQxbnLphg6eqUcDxRFCw1jpMdDY9qXlrwSs=
github.com/klauspost/compress v1.20.5/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/cpuid/v2 v2.4.2 h1:xRw7IZEsAgVCp6trS/DgWbTAqpixhmywgVgBjYGg1bQ=
github.com/klauspost/cpuid/v2 v2.4.2/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
github.com/klauspost/reedsolomon v1.14.2 h1:SafJYwpBBQBI6amHUygcjxZjXeN2HpiENHQDwuPWCCQ=
@@ -955,12 +955,12 @@ github.com/orcaman/concurrent-map/v2 v2.0.1 h1:jOJ5Pg2w1oeB6PeDurIYf6k9PQ+aTITr/
github.com/orcaman/concurrent-map/v2 v2.0.1/go.mod h1:9Eq3TG2oBe5FirmYWQfYO5iH1q0Jv47PLaNK++uCdOM=
github.com/panjf2000/ants/v2 v2.12.1 h1:BWvU2wHpyXWxhhNXsGB6JXLCNbshyLd1QxvoAmZnu10=
github.com/panjf2000/ants/v2 v2.12.1/go.mod h1:tSQuaNQ6r6NRhPt+IZVUevvDyFMTs+eS4ztZc52uJTY=
github.com/parquet-go/bitpack v1.0.0 h1:AUqzlKzPPXf2bCdjfj4sTeacrUwsT7NlcYDMUQxPcQA=
github.com/parquet-go/bitpack v1.0.0/go.mod h1:XnVk9TH+O40eOOmvpAVZ7K2ocQFrQwysLMnc6M/8lgs=
github.com/parquet-go/jsonlite v1.0.0 h1:87QNdi56wOfsE5bdgas0vRzHPxfJgzrXGml1zZdd7VU=
github.com/parquet-go/jsonlite v1.0.0/go.mod h1:nDjpkpL4EOtqs6NQugUsi0Rleq9sW/OtC1NnZEnxzF0=
github.com/parquet-go/parquet-go v0.32.0 h1:NWDqTUHfrCS4cJP/Fj2HlxvqsrVedWG3sayMkf+znzM=
github.com/parquet-go/parquet-go v0.32.0/go.mod h1:navtkAYr2LGoJVp141oXPlO/sxLvaOe3la2JEoD8+rg=
github.com/parquet-go/bitpack v1.1.1 h1:mygqlCBk/rnvtqqP5Oy7IkIPAxZ3bDM7V4yce/ms6pE=
github.com/parquet-go/bitpack v1.1.1/go.mod h1:XnVk9TH+O40eOOmvpAVZ7K2ocQFrQwysLMnc6M/8lgs=
github.com/parquet-go/jsonlite v1.5.7 h1:FxIrc2MBZ9QLpljM1+3F3JuCuug+BWOt8Yx+S4o3bl8=
github.com/parquet-go/jsonlite v1.5.7/go.mod h1:ZIyft0+sSdvgTu2m6RpqxWx/F3UBNtF3ammevxDJcoE=
github.com/parquet-go/parquet-go v0.33.0 h1:iDe13lcW6t0mnZWPqKqWccNa5GdP/L9GNNyzlr8JqNY=
github.com/parquet-go/parquet-go v0.33.0/go.mod h1:zl2XMxzSXZ5UYGfTLK0kvW0ifgVMPJ6I+/zmNnsOSh4=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
+2 -2
View File
@@ -898,7 +898,7 @@ func readPositionDeleteFile(
if readErr == io.EOF {
break
}
return nil, readErr
return nil, fmt.Errorf("read rows from %s: %w", filePath, readErr)
}
}
return result, nil
@@ -1038,7 +1038,7 @@ func readEqualityDeleteFile(
if readErr == io.EOF {
break
}
return nil, readErr
return nil, fmt.Errorf("read rows from %s: %w", filePath, readErr)
}
}
return result, nil
@@ -0,0 +1,307 @@
package iceberg
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"path"
"testing"
"time"
"github.com/apache/iceberg-go"
"github.com/apache/iceberg-go/table"
"github.com/parquet-go/parquet-go"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
)
// BOOLEAN columns that Arrow and parquet-mr write with data page v2 are
// RLE-encoded. parquet-go v0.32.0 read such a column wrong (a run's value
// expanded byte by byte, runs taken as multiples of 8 values) and wrote its own
// runs of trues with the value byte 0xFF, which DuckDB refuses ("Payload value
// bigger than allowed"). v0.33.0 reads and writes them as the format says.
//
// testdata/arrow-rle-boolean-{a,b}.parquet: pyarrow 25.0.1, data page v2, the
// boolean RLE encoding, zstd, 4 KB pages; ids 0-5999 and 6000-8999, field ids 1
// (id, long, required) and 2 (flag, boolean, optional). flag(id) is
// rleFixtureFlag.
func rleFixtureFlag(id int64) (value, null bool) {
if id%97 == 5 {
return false, true
}
r := id % 4112
switch {
case r < 1001:
return true, false
case r < 2000:
return false, false
case r < 2013:
return true, false
case r < 2016:
return false, false
}
return r%3 == 0, false
}
const (
rleFixtureIDField = 1
rleFixtureFlagField = 2
)
// readFlags reads (id, flag) from a Parquet file with this package's reader, by column name.
func readFlags(t *testing.T, name string, data []byte) map[int64]*bool {
t.Helper()
f, err := parquet.OpenFile(bytes.NewReader(data), int64(len(data)))
if err != nil {
t.Fatalf("%s: open: %v", name, err)
}
idCol, okID := f.Schema().Lookup("id")
flagCol, okFlag := f.Schema().Lookup("flag")
if !okID || !okFlag {
t.Fatalf("%s: no id or flag column", name)
}
out := map[int64]*bool{}
r := parquet.NewReader(f)
rows := make([]parquet.Row, 1024)
for {
n, err := r.ReadRows(rows)
for _, row := range rows[:n] {
var id int64
var flag *bool
for _, v := range row {
switch v.Column() {
case idCol.ColumnIndex:
id = v.Int64()
case flagCol.ColumnIndex:
if !v.IsNull() {
b := v.Boolean()
flag = &b
}
}
}
if _, dup := out[id]; dup {
t.Fatalf("%s: id %d read twice", name, id)
}
out[id] = flag
}
if err != nil {
if err != io.EOF {
t.Fatalf("%s: read rows: %v", name, err)
}
break
}
}
return out
}
func checkFlags(t *testing.T, what string, got map[int64]*bool, lo, hi int64) {
t.Helper()
if len(got) != int(hi-lo) {
t.Fatalf("%s: %d rows, want %d", what, len(got), hi-lo)
}
wrong := 0
first := int64(-1)
for id := lo; id < hi; id++ {
want, null := rleFixtureFlag(id)
g, ok := got[id]
if !ok || (g == nil) != null || (g != nil && *g != want) {
if first < 0 {
first = id
}
wrong++
}
}
if wrong > 0 {
t.Fatalf("%s: %d of %d flags wrong, the first at id %d", what, wrong, hi-lo, first)
}
}
func rleFixture(t *testing.T, name string) []byte {
t.Helper()
data, err := os.ReadFile(path.Join("testdata", name))
if err != nil {
t.Fatal(err)
}
return data
}
// The reader alone: both fixtures read back every flag.
func TestReadArrowRLEBooleans(t *testing.T) {
checkFlags(t, "fixture a", readFlags(t, "a", rleFixture(t, "arrow-rle-boolean-a.parquet")), 0, 6000)
checkFlags(t, "fixture b", readFlags(t, "b", rleFixture(t, "arrow-rle-boolean-b.parquet")), 6000, 9000)
}
// namedParquet is one data file of a table built by populateParquetTable.
type namedParquet struct {
name string
data []byte
rows int64
}
// populateParquetTable is a v2 unpartitioned table of the given Iceberg schema whose data files are the given Parquet
// files, in this order, one manifest each.
func populateParquetTable(t *testing.T, fs *fakeFilerServer, setup tableSetup, schema *iceberg.Schema, files []namedParquet) {
t.Helper()
spec := *iceberg.UnpartitionedSpec
location := "s3://" + setup.BucketName + "/" + setup.dataPath()
meta, err := table.NewMetadata(schema, &spec, table.UnsortedSortOrder, location, iceberg.Properties{"format-version": "2"})
if err != nil {
t.Fatal(err)
}
bucketPath := path.Join(s3tables.TablesPath, setup.BucketName)
tableFilerPath := path.Join(bucketPath, setup.dataPath())
metaDir, dataDir := path.Join(tableFilerPath, "metadata"), path.Join(tableFilerPath, "data")
putFile := func(dir, name string, data []byte) {
fs.putEntry(dir, name, &filer_pb.Entry{Name: name, Content: data,
Attributes: &filer_pb.FuseAttributes{Mtime: time.Now().Unix(), FileSize: uint64(len(data))}})
}
snapID := int64(1)
var manifests []iceberg.ManifestFile
for i, f := range files {
putFile(dataDir, f.name, f.data)
dfb, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData, setup.fileRef("data", f.name), iceberg.ParquetFile, map[int]any{}, nil, nil, f.rows, int64(len(f.data)))
if err != nil {
t.Fatal(err)
}
entry := iceberg.NewManifestEntry(iceberg.EntryStatusADDED, &snapID, nil, nil, dfb.Build())
mname := fmt.Sprintf("data-manifest-%d.avro", i)
var buf bytes.Buffer
mf, err := iceberg.WriteManifest(setup.fileRef("metadata", mname), &buf, 2, spec, schema, snapID, []iceberg.ManifestEntry{entry})
if err != nil {
t.Fatal(err)
}
putFile(metaDir, mname, buf.Bytes())
manifests = append(manifests, mf)
}
var mlBuf bytes.Buffer
seqNum := int64(1)
if err := iceberg.WriteManifestList(2, &mlBuf, snapID, nil, &seqNum, 0, manifests); err != nil {
t.Fatal(err)
}
putFile(metaDir, "snap-1.avro", mlBuf.Bytes())
snap := table.Snapshot{SnapshotID: snapID, SequenceNumber: 1, TimestampMs: time.Now().UnixMilli(),
ManifestList: setup.fileRef("metadata", "snap-1.avro"),
Summary: &table.Summary{Operation: table.OpAppend, Properties: map[string]string{}}}
builder, err := table.MetadataBuilderFromBase(meta, location)
if err != nil {
t.Fatal(err)
}
if err := builder.AddSnapshot(&snap); err != nil {
t.Fatal(err)
}
if err := builder.SetSnapshotRef(table.MainBranch, snapID, table.BranchRef); err != nil {
t.Fatal(err)
}
if meta, err = builder.Build(); err != nil {
t.Fatal(err)
}
full, _ := json.Marshal(meta)
xattr, _ := json.Marshal(map[string]interface{}{
"metadataVersion": 1,
"metadataLocation": setup.fileRef("metadata", "v1.metadata.json"),
"metadata": map[string]interface{}{"fullMetadata": json.RawMessage(full)},
})
fs.putEntry(s3tables.TablesPath, setup.BucketName, &filer_pb.Entry{
Name: setup.BucketName, IsDirectory: true, Extended: map[string][]byte{s3tables.ExtendedKeyTableBucket: []byte("true")},
})
fs.putEntry(bucketPath, setup.Namespace, &filer_pb.Entry{Name: setup.Namespace, IsDirectory: true})
fs.putEntry(path.Join(bucketPath, setup.Namespace), setup.TableName, &filer_pb.Entry{
Name: setup.TableName, IsDirectory: true, Extended: map[string][]byte{s3tables.ExtendedKeyMetadata: xattr},
})
}
// The compactor end to end: the two Arrow files merge into one, and every flag of the 9,000 rows survives.
func TestCompactKeepsArrowRLEBooleans(t *testing.T) {
fs, client := startFakeFiler(t)
setup := tableSetup{BucketName: "tb", Namespace: "ns", TableName: "flags"}
schema := iceberg.NewSchema(0,
iceberg.NestedField{ID: rleFixtureIDField, Type: iceberg.PrimitiveTypes.Int64, Name: "id", Required: true},
iceberg.NestedField{ID: rleFixtureFlagField, Type: iceberg.PrimitiveTypes.Bool, Name: "flag", Required: false},
)
populateParquetTable(t, fs, setup, schema, []namedParquet{
{"arrow-rle-boolean-a.parquet", rleFixture(t, "arrow-rle-boolean-a.parquet"), 6000},
{"arrow-rle-boolean-b.parquet", rleFixture(t, "arrow-rle-boolean-b.parquet"), 3000},
})
result := compactGeo(t, client, setup, Config{})
if want := "compacted 2 files into 1"; !bytes.Contains([]byte(result), []byte(want)) {
t.Fatalf("result %q, want %q", result, want)
}
outputs := compactedFiles(t, fs, setup)
if len(outputs) != 1 {
t.Fatalf("%d compacted files, want 1", len(outputs))
}
for name, data := range outputs {
checkFlags(t, "compacted "+name, readFlags(t, name, data), 0, 9000)
}
}
// testdata/arrow-plain-int32-{a,b}.parquet: pyarrow without dictionaries, so
// the INT32 and DATE column chunks list the encodings [RLE, PLAIN]. parquet-go
// v0.32.0 took the level encoding RLE as the column's encoding and the merge
// could not write ("RLE: cannot encode INT32 with invalid bit-width=0").
func TestCompactMergesNonDictionaryInt32AndDateColumns(t *testing.T) {
fs, client := startFakeFiler(t)
setup := tableSetup{BucketName: "tb", Namespace: "ns", TableName: "ints"}
schema := iceberg.NewSchema(0,
iceberg.NestedField{ID: 1, Type: iceberg.PrimitiveTypes.Int64, Name: "id", Required: true},
iceberg.NestedField{ID: 2, Type: iceberg.PrimitiveTypes.Int32, Name: "n", Required: false},
iceberg.NestedField{ID: 3, Type: iceberg.PrimitiveTypes.Date, Name: "d", Required: false},
)
populateParquetTable(t, fs, setup, schema, []namedParquet{
{"arrow-plain-int32-a.parquet", rleFixture(t, "arrow-plain-int32-a.parquet"), 2000},
{"arrow-plain-int32-b.parquet", rleFixture(t, "arrow-plain-int32-b.parquet"), 1000},
})
if result := compactGeo(t, client, setup, Config{}); !bytes.Contains([]byte(result), []byte("compacted 2 files into 1")) {
t.Fatalf("result %q", result)
}
firstDay := int32(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC).Unix() / 86400)
for name, data := range compactedFiles(t, fs, setup) {
f, err := parquet.OpenFile(bytes.NewReader(data), int64(len(data)))
if err != nil {
t.Fatal(err)
}
cols := map[string]int{}
for i, leaf := range f.Schema().Fields() {
cols[leaf.Name()] = i
}
r := parquet.NewReader(f)
rows := make([]parquet.Row, 512)
seen, wrong := map[int64]bool{}, 0
for {
n, err := r.ReadRows(rows)
for _, row := range rows[:n] {
var id int64
var num, day parquet.Value
for _, v := range row {
switch v.Column() {
case cols["id"]:
id = v.Int64()
case cols["n"]:
num = v
case cols["d"]:
day = v
}
}
if seen[id] || id < 0 || id >= 3000 {
wrong++
}
seen[id] = true
if (id%7 == 0) != num.IsNull() || (!num.IsNull() && int64(num.Int32()) != id) || day.Int32() != firstDay+int32(id%300) {
wrong++
}
}
if err != nil {
if err != io.EOF {
t.Fatalf("%s: read rows: %v", name, err)
}
break
}
}
if len(seen) != 3000 || wrong != 0 {
t.Fatalf("%s: %d distinct ids, %d wrong", name, len(seen), wrong)
}
}
}
@@ -83,9 +83,9 @@ func TestCompactRecordsGeometryBounds(t *testing.T) {
}
}
// A sorted rewrite may write its output without row-group geospatial
// statistics; the file then gets no geometry bound, never one that misses
// a row.
// A sorted rewrite whose bin fits the sort buffer is written by the sorting
// writer without spilling a run; its row groups keep their geospatial
// statistics and the file gets a geometry bound that covers every row.
func TestCompactSortedGeometryBoundCoversEveryRow(t *testing.T) {
fs, client := startFakeFiler(t)
setup := tableSetup{BucketName: "tb", Namespace: "ns", TableName: "geo"}
@@ -97,11 +97,21 @@ func TestCompactSortedGeometryBoundCoversEveryRow(t *testing.T) {
populateGeoTable(t, fs, setup, files, geoTableOptions{sortOrder: &so})
compactGeo(t, client, setup, Config{RewriteStrategy: "sort", SortBufferRows: minSortBufferRows})
geo, _ := compactedGeoBounds(t, client, setup)
if len(geo) == 0 {
t.Fatal("no compacted data file")
}
for p, got := range geo {
if got != nil && !got.covers(want) {
if got == nil {
t.Errorf("%s: no geometry bound on sorted output", p)
} else if !got.covers(want) {
t.Errorf("%s: geometry bound %s does not cover every geometry %s", p, got, want)
}
}
for name, data := range compactedFiles(t, fs, setup) {
if _, _, _, _, ok := footerGeoBox(t, data); !ok {
t.Errorf("%s: no row-group geometry statistics on sorted output", name)
}
}
}
func TestCompactAllNullGeometryGetsNoBound(t *testing.T) {
+9 -10
View File
@@ -14,17 +14,16 @@ import (
// A GEOMETRY column whose Iceberg type has the default CRS (OGC:CRS84) is
// written with no CRS in the Parquet logical type, as the input files from
// most writers declare it. parquet-go spells the default out when it writes
// such a column, even when the column it read declared none. Both mean the
// same, but a reader may then see the file column as a different type from
// the table column (DuckDB casts it and no longer prunes row groups by their
// statistics). An explicit CRS is left as it is.
// most writers declare it. parquet-go writes the CRS as the schema it is given
// declares it, so an output whose schema came from an input that spells the
// default out spells it out too. Both mean the same, but a reader may then see
// the file column as a different type from the table column (DuckDB casts it
// and no longer prunes row groups by their statistics). An explicit CRS is
// left as it is.
//
// The footer is changed after the file is written rather than by giving the
// writer another column type: parquet-go refuses to convert between two
// GEOMETRY types that both mean the default, and its sorting writer
// converts. Only the footer's schema elements change; the data, the page
// indexes and every offset into the file stay byte for byte.
// The footer is changed after the file is written: only the footer's schema
// elements change; the data, the page indexes and every offset into the file
// stay byte for byte.
var parquetMagic = []byte("PAR1")
+15 -14
View File
@@ -14,12 +14,15 @@ import (
)
// unsetDefaultCRS makes an input file declare the default CRS as no CRS at
// all, as DuckDB and other writers do; parquet.Geometry("") spells it out.
// all, as DuckDB and other writers do.
func unsetDefaultCRS(t *testing.T, data []byte) []byte {
t.Helper()
out, changed, err := withDefaultGeometryCRSUnset(data, geoTestSchema(iceberg.GeometryType{}))
if err != nil || !changed {
t.Fatalf("unset the input's default CRS: changed %v, %v", changed, err)
out, _, err := withDefaultGeometryCRSUnset(data, geoTestSchema(iceberg.GeometryType{}))
if err != nil {
t.Fatalf("unset the input's default CRS: %v", err)
}
if crs, ok := footerGeometryCRS(t, out, "geom"); !ok || crs != "" {
t.Fatalf("unset the input's default CRS: the file declares %q (geometry %v)", crs, ok)
}
return out
}
@@ -37,14 +40,12 @@ func fiveGeoFiles() []geoFile {
return files
}
// The Parquet CRS of a default-CRS geometry column survives compaction as the
// inputs declared it: none. The control shows what parquet-go does with the
// same schema on its own: it spells the default out.
// The Parquet CRS of a default-CRS geometry column is written as none, as most
// inputs declare it, even when one input spells the default out. The control
// shows what parquet-go does with such an input's schema on its own: it keeps
// the default spelled out.
func TestCompactWritesDefaultCRSGeometryWithoutCRS(t *testing.T) {
control := unsetDefaultCRS(t, writeGeoParquet(t, []geoRow{{1, wkbPoint(1, 2)}}, ""))
if crs, ok := footerGeometryCRS(t, control, "geom"); !ok || crs != "" {
t.Fatalf("setup: an input file declares CRS %q (geometry %v), want none", crs, ok)
}
control := writeGeoParquet(t, []geoRow{{1, wkbPoint(1, 2)}}, iceberg.DefaultGeoCRS)
f, err := parquet.OpenFile(bytes.NewReader(control), int64(len(control)))
if err != nil {
t.Fatal(err)
@@ -117,7 +118,7 @@ func TestCompactKeepsExplicitGeometryCRS(t *testing.T) {
func TestDefaultCRSUnsetForNestedGeometry(t *testing.T) {
schema := parquet.NewSchema("table", parquet.Group{
"id": parquet.FieldID(parquet.Compressed(parquet.Int(64), &zstd.Codec{}), 1),
"loc": parquet.FieldID(parquet.Group{"geom": parquet.FieldID(parquet.Optional(parquet.Geometry("")), 3)}, 2),
"loc": parquet.FieldID(parquet.Group{"geom": parquet.FieldID(parquet.Optional(parquet.Geometry(iceberg.DefaultGeoCRS)), 3)}, 2),
})
var buf bytes.Buffer
w := parquet.NewGenericWriter[any](&buf, schema)
@@ -175,7 +176,7 @@ func footerGeometryCRSs(t *testing.T, data []byte) map[string]string {
// A file without field ids is matched to the table by name: through the
// LIST and MAP wrapper groups too, which Iceberg's field names leave out.
func TestDefaultCRSUnsetWithoutFieldIDs(t *testing.T) {
geom := func() parquet.Node { return parquet.Optional(parquet.Geometry("")) }
geom := func() parquet.Node { return parquet.Optional(parquet.Geometry(iceberg.DefaultGeoCRS)) }
element := func(id int, typ iceberg.Type) *iceberg.ListType {
return &iceberg.ListType{ElementID: id, Element: typ, ElementRequired: false}
}
@@ -226,7 +227,7 @@ func TestDefaultCRSUnsetWithoutFieldIDs(t *testing.T) {
// as large as the target file size, and a copy of it would double the memory
// the rewrite needs.
func TestDefaultCRSUnsetReusesBuffer(t *testing.T) {
data := writeGeoParquet(t, []geoRow{{1, wkbPoint(1, 2)}, {2, wkbPoint(3, 4)}}, "")
data := writeGeoParquet(t, []geoRow{{1, wkbPoint(1, 2)}, {2, wkbPoint(3, 4)}}, iceberg.DefaultGeoCRS)
if crs, ok := footerGeometryCRS(t, data, "geom"); !ok || crs != iceberg.DefaultGeoCRS {
t.Fatalf("setup: CRS %q (geometry %v); the control is the spelled-out default", crs, ok)
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -62,7 +62,8 @@ func putInlineFile(t *testing.T, fs *fakeFilerServer, bucket, dataPath, file str
// corruptPageFile is a position delete file whose footer is intact but some
// bytes of its data pages are altered (the writer recorded no page CRC). It
// opens; decoding its rows panics inside parquet-go.
// opens; decoding its rows fails inside parquet-go (with an error since
// v0.33.0, with a panic before).
func corruptPageFile(t *testing.T) []byte {
t.Helper()
b, err := os.ReadFile("testdata/corrupt_page_deletes.parquet")
@@ -104,23 +105,6 @@ func TestUnopenableParquetFileIsAnErrorNotAPanic(t *testing.T) {
func TestCorruptPageIsAnErrorNamingTheFileNotAPanic(t *testing.T) {
body := corruptPageFile(t)
// Control: parquet-go itself panics while decoding this file's rows.
panicked := func() (p bool) {
defer func() { p = recover() != nil }()
r := parquet.NewReader(bytes.NewReader(body))
defer r.Close()
rows := make([]parquet.Row, 64)
for {
if _, err := r.ReadRows(rows); err != nil {
return false
}
}
}()
if !panicked {
t.Fatal("control: decoding the corrupt page no longer panics parquet-go; the test file needs replacing")
}
fs, client := startFakeFiler(t)
const bucket, dataPath, file = "b", "ns/t", "data/corrupt-deletes.parquet"
putInlineFile(t, fs, bucket, dataPath, file, body)
@@ -128,7 +112,7 @@ func TestCorruptPageIsAnErrorNamingTheFileNotAPanic(t *testing.T) {
noPanic(t, func() {
_, err = readPositionDeleteFile(context.Background(), client, bucket, dataPath, file)
})
if err == nil || !strings.Contains(err.Error(), file) || !strings.Contains(err.Error(), "panic") {
if err == nil || !strings.Contains(err.Error(), file) {
t.Fatalf("err = %v, want an error naming %s", err, file)
}
}
@@ -257,7 +241,7 @@ func TestMergeFailsOnACorruptPageNamingTheFile(t *testing.T) {
Content: corruptPageFile(t),
})
// Its footer reads fine, so the panic comes from its pages inside the
// Its footer reads fine, so the failure comes from its pages inside the
// merge's row decoder.
var err error
noPanic(t, func() {
@@ -265,7 +249,7 @@ func TestMergeFailsOnACorruptPageNamingTheFile(t *testing.T) {
[]iceberg.ManifestEntry{schemaFileEntry(t, "data/corrupt.parquet", 1)},
nil, nil, newTestSchema(), 0, false, nil)
})
if err == nil || !strings.Contains(err.Error(), "corrupt.parquet") || !strings.Contains(err.Error(), "panic") {
if err == nil || !strings.Contains(err.Error(), "corrupt.parquet") {
t.Fatalf("err = %v, want an error naming corrupt.parquet", err)
}
}