ShivamSharma43 opened a new pull request, #2717:
URL: https://github.com/apache/iceberg-go/pull/2717

   Date, time and timestamp column defaults did not use the spec's JSON form in 
either direction (see #2715 for the reproduction):
   
   - **Writing.** `AddColumn` stores the default literal's `Any()` value, an 
`iceberg.Date`, `Time`, `Timestamp` or `TimestampNano`, and 
`NestedField.MarshalJSON` wrote it as the underlying integer, for example 
`"initial-default":17486`. Java's `SchemaParser` reads defaults with 
`SingleValueParser`, which only accepts a string for these types, so Java could 
not load the table's metadata.
   - **Reading.** A spec-following writer such as Java stores 
`"initial-default":"2017-11-16"`. Scanning a data file written before that 
column existed failed in `defaultToScalar` with `unsupported write-default 
value type string for numeric iceberg type`. Filters on such a column already 
accepted the string form (`initialDefaultLiteral`, covered by the "matching ISO 
date default" cases in `visitors_test.go`); only the projection did not.
   
   ### Fix
   
   - `defaultValueToJSON` now writes these defaults as the spec's [JSON 
single-value 
serialization](https://iceberg.apache.org/spec/#json-single-value-serialization):
 `"2017-11-16"`, `"22:31:08.123456"`, `"2017-11-16T22:31:08.123456"`, 
`"2017-11-16T22:31:08.123456+00:00"`, and nine fractional digits for 
`timestamp_ns`/`timestamptz_ns`. A numeric default read from metadata written 
by older iceberg-go versions (a `float64`) is written back as a string too, so 
the next metadata write repairs it.
   - `defaultToScalar` parses a string default for these types with the 
existing string-to-literal casts before the numeric handling. Numeric defaults 
still read as before.
   - Compatibility note in `website/src/releases.md`: older iceberg-go releases 
can't scan a table with such a default once this version has written it.
   
   Java reference: 
[`SingleValueParser.toJson`](https://github.com/apache/iceberg/blob/6cf1f6e4e6cfa6210f0017466283be6d01acab68/core/src/main/java/org/apache/iceberg/SingleValueParser.java#L287-L313)
 writes `daysToIsoDate`, `microsToIsoTime`, `microsToIsoTimestamp(tz)` and 
`nanosToIsoTimestamp(tz)` strings, and 
[`fromJson`](https://github.com/apache/iceberg/blob/6cf1f6e4e6cfa6210f0017466283be6d01acab68/core/src/main/java/org/apache/iceberg/SingleValueParser.java#L121-L156)
 rejects anything that isn't textual (`Cannot parse default as a date value: 
...`); 
[`SchemaParser`](https://github.com/apache/iceberg/blob/6cf1f6e4e6cfa6210f0017466283be6d01acab68/core/src/main/java/org/apache/iceberg/SchemaParser.java#L200)
 uses it for `initial-default` and `write-default`.
   
   ### Testing
   
   - `TestNestedFieldMarshalTemporalDefaultsAsISOStrings` (`types_test.go`) 
marshals each temporal type's default, including a date before 1970, checks the 
string, and parses it back to the same value. 
`TestNestedFieldRewritesLegacyNumericTemporalDefault` loads 
`"initial-default":17486` and checks it is written as `"2017-11-16"`.
   - `TestToRequestedSchemaInitialDefaultJSONRoundTrip` 
(`table/arrow_utils_test.go`) gains ISO-string cases for all six types next to 
the existing numeric ones.
   - `TestAddColumnTemporalDefaultsSurviveMetadataRoundTrip` 
(`table/update_schema_test.go`) adds a file to a v3 table, adds `date` and 
`timestamp` columns with defaults, reloads the metadata JSON as a catalog 
would, checks the strings, and scans with a filter on the date column: the old 
file reads both defaults.
   
     All of these fail on main and pass with the fix.
   - `go vet` is clean for the root and `table` packages. `go test .` passes. 
`go test ./table/` passes except for 29 tests that fail the same way on 
unmodified main on Windows, where the temp directory's drive letter becomes a 
`file://D:\...` URL or the hadoop warehouse scheme `"d"` (for example 
`TestComputeNDVs*`, `TestVariantExtract*`, `TestTable`, `TestWriteMapType`, 
`TestScanWithIDLessNameMappingFields`). None of them involve column defaults.
   
   Closes #2715
   
   This PR was prepared with AI assistance (Claude Code).
   
   🤖 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]

Reply via email to