{"record":{"id":"4fd11076de5245a7","repo":"apache/iceberg","slug":"unable-to-create-table-from-empty-object","errorCode":null,"errorMessage":"Unable to create table from empty object","messagePattern":"Unable to create table from empty object","errorType":"exception","errorClass":"DataException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java","lineNumber":89,"sourceCode":"\n    UUID tableUuid = table.uuid();\n    if (tableUuid == null) {\n      LOG.warn(\n          \"Table {} does not have a UUID, this may cause issues with commit coordination on table replace\",\n          identifier);\n    }\n    TableReference tableReference = TableReference.of(catalog.name(), identifier, tableUuid);\n\n    return new IcebergWriter(table, tableReference, config);\n  }\n\n  @VisibleForTesting\n  Table autoCreateTable(String tableName, SinkRecord sample) {\n    StructType structType;\n    if (sample.valueSchema() == null) {\n      Type type = SchemaUtils.inferIcebergType(sample.value(), config);\n      if (type == null) {\n        throw new DataException(\"Unable to create table from empty object\");\n      }\n      structType = type.asStructType();\n    } else {\n      structType = SchemaUtils.toIcebergType(sample.valueSchema(), config).asStructType();\n    }\n\n    org.apache.iceberg.Schema schema = new org.apache.iceberg.Schema(structType.fields());\n    TableIdentifier identifier = TableIdentifier.parse(tableName);\n\n    createNamespaceIfNotExist(catalog, identifier.namespace());\n\n    List<String> partitionBy = config.tableConfig(tableName).partitionBy();\n    PartitionSpec spec;\n    try {\n      spec = SchemaUtils.createPartitionSpec(schema, partitionBy);\n    } catch (Exception e) {\n      LOG.error(\n          \"Unable to create partition spec {}, table {} will be unpartitioned\",","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java#L71-L107","documentation":"IcebergWriterFactory.autoCreateTable infers the Iceberg schema for the new table from a sample SinkRecord. When the record has no value schema, it infers the type from the raw value; if that inference returns null (value is null or an empty/unsupported object), table creation cannot proceed and a DataException is thrown.","triggerScenarios":"auto-create-table is enabled and the sampled record's valueSchema() is null while its value() yields no inferable type — e.g. null payloads (tombstones), empty maps/structs, or unsupported value shapes reaching the sampler.","commonSituations":"Topic's first/most recent record is a tombstone (null value) at connector start; producer sending schema-less formats (raw JSON/bytes) with empty objects; misconfigured value converter producing null values.","solutions":["Pre-create the target Iceberg table with an explicit schema instead of relying on auto-creation.","Ensure the topic carries records with real, non-null, non-empty values and a value schema (use Avro/Protobuf with schema registry, or ensure JSON converter emits schemas).","Check the producer/converter config so tombstones or empty messages are not the records used for schema inference.","Verify table_create/auto-create properties point at the correct topic-to-table mapping with a valid sample record available."],"exampleFix":"// before\n// auto-create from a topic whose sampled record has null schema/value\n// \"iceberg.sink.auto-create-table\": \"true\"\n\n// after\n// pre-create the table explicitly\nspark.sql(\"CREATE TABLE catalog.db.topic_table (id long, ts timestamp) USING iceberg\");","handlingStrategy":"validation","validationCode":"// Java — check the sample before relying on auto-creation\nboolean canAutoCreate = sample.value() != null &&\n    (sample.valueSchema() != null || sample.value() instanceof Map && !((Map<?, ?>) sample.value()).isEmpty());","typeGuard":null,"tryCatchPattern":"try {\n  Table table = factory.autoCreateTable(tableName, sample);\n} catch (DataException e) {\n  if (String.valueOf(e.getMessage()).contains(\"Unable to create table from empty object\")) {\n    LOG.error(\"Sample record has no schema/empty value — pre-create table {} explicitly\", tableName, e);\n  }\n  throw e;\n}","preventionTips":["Pre-create Iceberg tables with explicit schemas instead of auto-creating from topic samples","Use schema-carrying formats (Avro/Protobuf + schema registry) on the source topic","Ensure tombstones/empty messages are not the records sampled at connector start","Verify the value converter is configured to emit schemas (e.g. schemas.enable=true for JSON)"],"tags":["kafka-connect","table-creation","schema-inference","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}