Repository navigation
fix: write decimal column defaults as strings in metadata JSON - #2696
Open
ShivamSharma43 wants to merge 1 commit into
Open
ShivamSharma43 wants to merge 1 commit into
ShivamSharma43 wants to merge 1 commit into
Conversation
iceberg.Decimal has no JSON encoding and its decimal128 value has no
exported fields, so a decimal initial-default or write-default was
written as {"Val":{},"Scale":2} and the value was lost. Write the
spec's single-value form, a string such as "14.20", as Java's
SingleValueParser does.
Closes apache#2695
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A decimal column default was lost when table metadata was written as JSON.
AddColumnstores the default literal'sAny()value, which for a decimal is aniceberg.Decimal, andNestedField.MarshalJSONwrote it as{"Val":{},"Scale":2}. After a catalog reloads the metadata, the default is gone, and scanning a data file written before the column existed fails instead of returning the default (see the issue for the reproduction).Cause
defaultValueToJSONpasses every value that isn't hex-encoded through unchanged.iceberg.Decimalhas no JSON encoding of its own, and itsdecimal128.Numhas no exported fields, soencoding/jsonwrites the empty struct and the scale.Fix
defaultValueToJSONnow writes aniceberg.DecimalasDecimal.String(), for example"14.20"or"-0.05". That is the spec's JSON single-value serialization fordecimal(P, S), and what Java'sSingleValueParserwrites. Reading is unchanged: a string default was already parsed for decimal fields.Testing
TestNestedFieldMarshalDecimalDefaultsAsStringintypes_test.gomarshals a field with decimal initial and write defaults, checks the JSON, and decodes it back.TestAddColumnDecimalDefaultSurvivesMetadataRoundTripintable/update_schema_test.goadds a file to a v3 table, adds adecimal(9, 2)column with default14.20, reloads the table from its metadata JSON, and scans: the old file reads14.20for the new column.Both fail on main (the JSON holds
{"Val":{},"Scale":2}, and the scan returns an error) and pass with the fix.go vetis clean for the root andtablepackages.go test .passes.go test ./table/passes except for tests that fail the same way on unmodified main on Windows (the drive letter is read as a URL scheme):TestEmptyStringIdentityPartitionScans,TestScanImportedSignedZeroBounds,TestDeleteImportedSignedZerosWithIn,TestDeleteNormallyWrittenSignedZeroWithIn,TestScanLegacyEmptyStringPartitionDeleteBounds,TestScanWithIDLessNameMappingFields, twoTestRewriteDataFiles_PartialProgress*tests andTestWriteMapType.Closes #2695
This PR was prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code