huan233usc opened a new pull request, #17259: URL: https://github.com/apache/iceberg/pull/17259
The spec requires columns of `unknown`, `variant`, `geometry`, and `geography` types to default to null: "All columns of `unknown`, `variant`, `geometry`, and `geography` types must default to null. Non-null values for `initial-default` or `write-default` are invalid." `NestedField.castDefault` handled this inconsistently across those four types: - `unknown`, `geometry`, and `geography` fell through to `Literal.to(type)`, which returns `null` for these types, so a non-null default was rejected with the misleading message `Cannot cast default value to <type>: <value>`. That reads like a value-conversion failure rather than "this type cannot carry a default at all." - `variant`'s `Literal.to(VARIANT)` returns the literal itself, so a non-null variant default was **not rejected**. It is only unreachable today because there is no public variant `Literal` factory and `SingleValueParser` rejects variant defaults on the JSON path — but the constructor-level guard was missing. This routes all four types (plus nested types, which were already rejected) through a single `supportsDefaultValue` check that throws the clearer, spec-aligned message `Invalid default value for <type>: <value> (must be null)`, reusing the wording already used for nested types. Valid defaults on all other primitive types are unaffected — they still go through `Literal.to(type)`. There is no behavior change for the types that were already rejected, other than a clearer message; the only behavioral fix is closing the variant gap at the field constructor. ## Testing - `TestSchema.testGeospatialTypesRejectNonNullDefault` — the `CREATE TABLE` / field-constructor path, covering both `initial-default` and `write-default` for geometry and geography. - `TestSchema.testVariantTypeRejectsNonNullDefault` — variant default rejected at the constructor. - `TestSchemaUpdate.testAddGeometryNonNullDefault` / `testAddGeographyNonNullDefault` — the `addColumn` (schema evolution) path. - `TestSchemaUpdate.testAddUnknownNonNullDefault` — existing test updated to the new message. All pass locally (`iceberg-api` and `iceberg-core` test suites, spotless clean). -- 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]
