wombatu-kun commented on code in PR #16598:
URL: https://github.com/apache/iceberg/pull/16598#discussion_r3371535675
##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/IcebergWriterFactory.java:
##########
@@ -93,7 +96,55 @@ Table autoCreateTable(String tableName, SinkRecord sample) {
structType = SchemaUtils.toIcebergType(sample.valueSchema(),
config).asStructType();
}
- org.apache.iceberg.Schema schema = new
org.apache.iceberg.Schema(structType.fields());
+ List<String> idColumns = config.tableConfig(tableName).idColumns();
+
+ if (!idColumns.isEmpty() && config.schemaForceOptional()) {
+ throw new DataException(
+ String.format(
+ "iceberg.tables.schema-force-optional is enabled for table %s
but id-columns are configured. "
+ + "schema-force-optional marks every field optional, which
is incompatible with identifier fields that must be required. "
+ + "Disable schema-force-optional or remove the id-columns
configuration.",
+ tableName));
+ }
+
+ org.apache.iceberg.Schema initialSchema = new
org.apache.iceberg.Schema(structType.fields());
Review Comment:
initialSchema is constructed only to resolve column names to field ids and
to list columns in the not-found message, then discarded; the table is built
from the second Schema on line 139. structType already exposes both:
structType.field(name) returns the same NestedField and structType.fields() the
same column list. The ids match because this constructor does not reassign them
when getID is null (Schema.java:578). Dropping initialSchema and using
structType directly is equivalent here since dotted paths are rejected just
above, so only top-level names reach the lookup.
--
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]