riverandeye opened a new issue, #2708:
URL: https://github.com/apache/iceberg-go/issues/2708
When a string or binary column's minimum or maximum is `""` (or empty
binary), the data file is written without that bound. If every value in the
file is empty, the file gets neither bound, so filters such as `s = 'x'`, `s >
'a'` or `s != ''` can't skip it. Results are still correct, since a missing
bound is treated as unknown.
Reproduced on main (0cbb5af):
```go
sc := iceberg.NewSchema(0,
iceberg.NestedField{ID: 1, Name: "id", Type:
iceberg.PrimitiveTypes.Int64, Required: true},
iceberg.NestedField{ID: 2, Name: "s", Type:
iceberg.PrimitiveTypes.String},
)
tbl, _ := cat.CreateTable(ctx, catalog.ToIdentifier("db", "t"), sc)
// append rows (1, "") and (2, "")
tbl, _ = tbl.Append(ctx, rdr, nil)
tasks, _ := tbl.Scan().PlanFiles(ctx)
fmt.Println("lower:", tasks[0].File.LowerBoundValues())
fmt.Println("upper:", tasks[0].File.UpperBoundValues())
tasks, _ =
tbl.Scan(table.WithRowFilter(iceberg.EqualTo(iceberg.Reference("s"),
"zz"))).PlanFiles(ctx)
fmt.Println("files for s = 'zz':", len(tasks))
```
Output:
```
lower: map[1:[1 0 0 0 0 0 0 0]]
upper: map[1:[2 0 0 0 0 0 0 0]]
files for s = 'zz': 1
```
Expected: both maps also have `2:[]`, and `s = 'zz'` plans no files. Java
writes empty bounds for the same rows. It only skips a bound that is `null`
([`ParquetMetrics.java`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/parquet/src/main/java/org/apache/iceberg/parquet/ParquetMetrics.java#L161-L171)):
```java
if (metrics.lowerBound() != null) {
ByteBuffer lowerBound =
Conversions.toByteBuffer(metrics.originalType(), metrics.lowerBound());
lowerBounds.put(id, lowerBound);
}
```
I checked this by writing the same rows with both libraries and reading the
manifests with a plain Avro reader: Java has `2=0x` in both `lower_bounds` and
`upper_bounds`, iceberg-go has neither. With those bounds, Java's
`InclusiveMetricsEvaluator` skips the file for `s = 'zz'`, `s > 'a'`,
`startsWith(s, 'a')` and `s != ''`, and `StrictMetricsEvaluator` reports that
every row matches `s = ''`. Without them, it can do neither.
When only some values are empty (rows `""` and `"z"`), iceberg-go drops just
the lower bound. That doesn't change pruning, since `""` is the smallest
string, but the manifest still differs from Java's.
**Cause**
An empty value serializes to zero bytes, so the length check can't tell it
apart from "no bound"
([`table/internal/utils.go`](https://github.com/apache/iceberg-go/blob/0cbb5affc36f116204f44b982df4d2d132029729/table/internal/utils.go#L349-L356)):
```go
min := must(agg.MinAsBytes())
max := must(agg.MaxAsBytes())
if len(min) > 0 {
lowerBounds[fieldID] = min
}
if len(max) > 0 {
upperBounds[fieldID] = max
}
```
`MaxAsBytes` does the same one step earlier: it treats an empty truncation
result as "no upper bound", even when the input was `""` and nothing was
truncated
([`table/internal/utils.go`](https://github.com/apache/iceberg-go/blob/0cbb5affc36f116204f44b982df4d2d132029729/table/internal/utils.go#L541-L559)):
```go
result := TruncateUpperBoundText(curMax, s.truncLen)
if result != "" {
return s.toBytes(iceberg.StringLiteral(result))
}
return nil, nil
```
The binary case has the same `len(result) > 0` check.
**Proposed fix:** check for `nil` instead of length, keep empty values
non-nil in `toBytes` (`StringLiteral.MarshalBinary` already returns a non-nil
slice for `""`), and have `MaxAsBytes` return `nil` only when truncation found
no upper bound.
--
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]