iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

`initial-default`+`write-default` `{}` (struct default value) representation issue

Open Tishj opened this issue 6 months ago • 2 comments

Apache Iceberg version

1.11.0 (latest release)

Query engine

None

Please describe the bug 🐞

This issue is similar to https://github.com/apache/iceberg/issues/15932

The spec has a very clear table listing behavior for struct defaults, and makes it clear that a struct column can either have null as its default value, or {}, the default values for its fields should be decomposed.

A non-null default is stored by setting initial-default or write-default to an empty struct ({}) that will use field values set from each field's initial-default or write-default, respectively.

But in the Iceberg REST API spec, both initial-default and write-default are modeled as a PrimitiveTypeValue:

        initial-default:
          $ref: "#/components/schemas/PrimitiveTypeValue"
        write-default:
          $ref: "#/components/schemas/PrimitiveTypeValue"

So I don't think we can currently represent {} for an initial-default or write-default

Example request:

{
	"stage-create": true,
	"name": "tbl",
	"schema": {
		"type": "struct",
		"fields": [
			{
				"name": "col",
				"id": 1,
				"type": {
					"type": "struct",
					"fields": [
						{
							"name": "a",
							"id": 2,
							"type": "string",
							"required": false,
							"initial-default": "test"
						},
						{
							"name": "b",
							"id": 3,
							"type": "int",
							"required": false
						}
					]
				},
				"required": false,
				"initial-default": {}
			},
			{
				"name": "col2",
				"id": 4,
				"type": "int",
				"required": false
			}
		],
		"schema-id": 0
	},
	"partition-spec": {
		"spec-id": 0,
		"type": "struct",
		"fields": []
	},
	"write-order": {
		"order-id": 0,
		"fields": []
	},
	"properties": {
		"format-version": "3"
	}
}

Attempting to POST this to the create table endpoint targeting an iceberg-rest-fixture catalog results in a long Internal Error message, of which an excerpt is:

Cannot create expression literal from org.apache.iceberg.data.GenericRecord: Record(null, null)

Willingness to contribute

  • [ ] I can contribute a fix for this bug independently
  • [ ] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • [x] I cannot contribute a fix for this bug at this time

Tishj avatar May 28 '26 13:05 Tishj

Bump

Tishj avatar Jul 29 '26 16:07 Tishj

I'd like to pick this up, since #16612 was closed by the stale bot. Java can't represent a non-null struct default today: SchemaParser turns {} into a GenericRecord that Expressions.lit rejects, and NestedField only accepts null defaults for nested types. Following the review on #16612, I'd add an empty-struct default literal to Literals behind a public factory, accept it as a struct field default, read and write {} in SchemaParser, and allow it for initial-default and write-default in the REST spec. @nssalian does that direction work for you?

binarybrain-009 avatar Oct 29 '26 02:10 binarybrain-009