Files
seaweedfs/weed/worker/tasks/iceberg/compact_rowgroup_test.go
T
3da9c41404 iceberg maintenance: worker setting for the row-group size of compacted files (#13128)
* iceberg maintenance: worker setting for the row-group size of compacted files

Compaction takes a compacted file's row-group size from the table property `write.parquet.row-group-size-bytes`, and falls back to Iceberg's default, 128 MB, when the table sets none. Most tables set none, and the default target file size is also around 128 MB, so a compacted file usually comes out as a single row group. A reader's column filter (a time range, an id range) can then skip the whole file or nothing inside it.

Setting the property table by table is the only way to change that today. This adds a worker setting, `row_group_size_mb`, that sets the size for tables without the property:

- default 0 = Iceberg's 128 MB, so nothing changes unless an operator sets it;
- the table property still wins over it, so an engine or a user that chose a size keeps it;
- `write.parquet.row-group-limit` (rows) is untouched.

For example, `row_group_size_mb = 64` gives about two row groups per 128 MB compacted file.

Test: `TestRowGroupSizeWorkerSettingAndTableOverride` (the default is 0, the setting is read, a table without the property gets the worker's size, the property wins).

`go vet ./weed/worker/tasks/iceberg` and `go test ./weed/worker/tasks/iceberg` pass; `go build ./weed` builds.

* iceberg maintenance: raise the descriptor version with row_group_size_mb

The admin keeps a stored descriptor unless the new one's version is not
lower. With both at 1, an older worker serving a descriptor refresh during a
rolling upgrade replaced the form and row_group_size_mb disappeared. The
test fails at version 1.

* iceberg maintenance: say row_group_size_mb also caps the spatial row group size

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

* iceberg maintenance: keep at least one row per row group when a row outgrows the byte size

With an explicit row limit the estimate had no floor, so a byte size
smaller than one row gave 0, which parquet-go takes as no limit.

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

* iceberg maintenance: say row_group_size_mb only caps a spatial rewrite's row groups

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>
2026-11-30 11:33:32 -08:00

102 lines
3.4 KiB
Go

package iceberg
import (
"bytes"
"context"
"fmt"
"testing"
"github.com/apache/iceberg-go"
"github.com/parquet-go/parquet-go"
)
// Compacted files get row groups from the table's
// write.parquet.row-group-limit instead of one row group per file.
func TestCompactDataFilesWritesSeveralRowGroups(t *testing.T) {
fs, client := startFakeFiler(t)
setup := tableSetup{BucketName: "tb", Namespace: "ns", TableName: "tbl"}
type rowsT = struct {
ID int64
Name string
}
makeRows := func(lo, hi int64) []rowsT {
rows := make([]rowsT, 0, hi-lo)
for i := lo; i < hi; i++ {
rows = append(rows, rowsT{i, fmt.Sprintf("r%d", i)})
}
return rows
}
populateTableWithDeleteFiles(t, fs, setup,
[]struct {
Name string
Rows []rowsT
}{
{"d1.parquet", makeRows(0, 1500)},
{"d2.parquet", makeRows(1500, 3000)},
},
nil, nil,
)
handler := NewHandler(nil)
config := Config{
TargetFileSizeBytes: 256 * 1024 * 1024,
MinInputFiles: 2,
MaxCommitRetries: 3,
RowGroupRowLimit: 2000,
}
if _, _, err := handler.compactDataFiles(context.Background(), client, setup.BucketName, setup.tablePath(), config, nil); err != nil {
t.Fatalf("compactDataFiles: %v", err)
}
state, err := loadCurrentMetadata(context.Background(), client, setup.BucketName, setup.tablePath())
if err != nil {
t.Fatalf("loadCurrentMetadata: %v", err)
}
df := compactedDataFile(t, client, setup)
data, err := loadFileByIcebergPath(context.Background(), client, setup.BucketName, state.DataPath, df.FilePath())
if err != nil {
t.Fatalf("load compacted file: %v", err)
}
f, err := parquet.OpenFile(bytes.NewReader(data), int64(len(data)))
if err != nil {
t.Fatalf("open compacted file: %v", err)
}
if got := len(f.Metadata().RowGroups); got != 2 {
t.Errorf("row groups = %d, want 2 (3000 rows at row-group-limit 2000)", got)
}
}
// A configured row-group limit is a cap, not a floor: small explicit limits
// are honored instead of being raised to the estimate floor.
func TestRowsPerRowGroupHonorsConfiguredLimit(t *testing.T) {
entries := make([]iceberg.ManifestEntry, 0, 2)
spec := *iceberg.UnpartitionedSpec
for _, name := range []string{"a.parquet", "b.parquet"} {
dfb, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData,
"s3://b/data/"+name, iceberg.ParquetFile, map[int]any{}, nil, nil, 300, 9000)
if err != nil {
t.Fatalf("build data file: %v", err)
}
snapID := int64(1)
entries = append(entries, iceberg.NewManifestEntry(iceberg.EntryStatusADDED, &snapID, nil, nil, dfb.Build()))
}
bin := compactionBin{Entries: entries, TotalSize: 18000}
if got := rowsPerRowGroup(bin, Config{RowGroupRowLimit: 128}); got != 128 {
t.Errorf("explicit limit: rowsPerRowGroup = %d, want 128", got)
}
// 30 bytes/row, byte cap 128MB: the estimate of ~4.4M rows exceeds the 2M
// default, so the default holds; the floor lifts a degenerate estimate.
if got := rowsPerRowGroup(bin, Config{RowGroupSizeBytes: 1024}); got != minRowGroupRows {
t.Errorf("floored estimate: rowsPerRowGroup = %d, want %d", got, minRowGroupRows)
}
if got := rowsPerRowGroup(bin, Config{}); got != defaultRowGroupRowLimit {
t.Errorf("default: rowsPerRowGroup = %d, want %d", got, defaultRowGroupRowLimit)
}
// Rows larger than the byte size: zero would mean no limit to the writer.
if got := rowsPerRowGroup(bin, Config{RowGroupRowLimit: 10, RowGroupSizeBytes: 16}); got != 1 {
t.Errorf("rows larger than the byte size: rowsPerRowGroup = %d, want 1", got)
}
}