ShivamSharma43 opened a new issue, #2715:
URL: https://github.com/apache/iceberg-go/issues/2715

   ### Apache Iceberg version
   
   main (development)
   
   ### Please describe the bug 🐞
   
   Date, time and timestamp column defaults are written to metadata JSON as 
numbers, and the spec's string form can't be read back.
   
   **Writing.** `AddColumn` stores the default literal's `Any()` value, which 
for these types is an `iceberg.Date`, `iceberg.Time`, `iceberg.Timestamp` or 
`iceberg.TimestampNano`. `NestedField.MarshalJSON` passes it through 
`defaultValueToJSON` unchanged, so `encoding/json` writes the underlying 
integer (days or micro/nanoseconds). Reproduced on main (0cbb5af):
   
   ```go
   lit, _ := iceberg.NewLiteral("2017-11-16").To(iceberg.PrimitiveTypes.Date)
   field := iceberg.NestedField{ID: 1, Name: "day", Type: 
iceberg.PrimitiveTypes.Date,
        InitialDefault: lit.Any(), WriteDefault: lit.Any()}
   out, _ := json.Marshal(field)
   fmt.Println(string(out))
   ```
   
   Output:
   
   ```
   
{"type":"date","id":1,"name":"day","required":false,"initial-default":17486,"write-default":17486}
   ```
   
   Expected `"initial-default":"2017-11-16"`. The spec's [JSON single-value 
serialization](https://iceberg.apache.org/spec/#json-single-value-serialization)
 writes `date`, `time`, `timestamp`, `timestamptz`, `timestamp_ns` and 
`timestamptz_ns` as ISO-8601 strings (`"2017-11-16"`, `"22:31:08.123456"`, 
`"2017-11-16T22:31:08.123456"`, `"2017-11-16T22:31:08.123456+00:00"`, ...). 
Java's 
[`SingleValueParser`](https://github.com/apache/iceberg/blob/6cf1f6e4e6cfa6210f0017466283be6d01acab68/core/src/main/java/org/apache/iceberg/SingleValueParser.java#L121-L156)
 only accepts a string for these types 
(`Preconditions.checkArgument(defaultValue.isTextual(), "Cannot parse default 
as a %s value: %s", ...)`), and `SchemaParser` uses it for 
`initial-default`/`write-default`, so Java can't load the metadata of a table 
whose date or timestamp column was added with a default by iceberg-go.
   
   **Reading.** The other direction fails too. A table created by Java (or any 
spec-following writer) has `"initial-default":"2017-11-16"`. When iceberg-go 
scans a data file written before that column existed, `defaultToScalar` in 
`table/arrow_utils.go` only accepts a typed value or a JSON number for temporal 
types (`numericDefault`), so the scan fails with `unsupported write-default 
value type string for numeric iceberg type`. `UpdateSchema.UnionByName` checks 
the defaults of the columns it adds with the same function.
   
   I'd like to work on this. I have a fix and tests ready.
   


-- 
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