ShivamSharma43 opened a new pull request, #2458: URL: https://github.com/apache/iceberg-go/pull/2458
Converting a string literal to a decimal rounded it to the type's scale with no error. A predicate bound with more fractional digits than the column's scale was rounded too, so filters returned wrong rows. For example, `price > "12.345"` on a `decimal(9, 2)` column bound as `price > 12.35` and dropped rows where `price = 12.35`. Decimal values in expression JSON are strings, so `ParseExpr` hits this as well. ### Cause `StringLiteral.To(DecimalType)` calls arrow's `decimal128.FromString(s, precision, scale)`, which scales the value, adds or subtracts 0.5 and truncates. ### Fix `StringLiteral.To` now returns `ErrBadCast` when the string needs more fractional digits than the scale allows. The digit count comes from the string itself: fractional digits minus the exponent, ignoring trailing zeros. A small helper, `decimalStringScale`, does this without building big numbers from the exponent. Strings the scale represents exactly convert the same as before: `"12.3"` gives `12.30`, and `"12.340"`, `"1234e-2"` and `"0e-5"` are all accepted. Java keeps the exact `BigDecimal` here, and PyIceberg raises when the scales differ. Neither one rounds. Rejecting only lossy values is the smallest change that stops the wrong results. If you'd rather require an exact scale match like PyIceberg, I'm happy to tighten it. ### Testing - New `TestStringLiteralToDecimalScale` covers exact values (with and without trailing zeros or exponents, negatives, zero) and lossy values that must fail with `ErrBadCast`. It also checks that `BindExpr` rejects `price > "12.345"`. The lossy cases fail on main. - `go vet` and `golangci-lint run` (v2.14.0) are clean. `go test ./...` passes except for `TestWriteMapType` and `TestGetReferencedFiles_OverwriteThenExpireExcludesTombstones`. Both also fail on unmodified main on my Windows machine, because of path handling. Closes #2457 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
