You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "fqaiser94 (via GitHub)" <gi...@apache.org> on 2024/06/06 17:33:05 UTC

[PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

fqaiser94 opened a new pull request, #10456:
URL: https://github.com/apache/iceberg/pull/10456

   If a column is present in the table but missing from a record, we should mark the column as optional on the table. 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

Posted by "tabmatfournier (via GitHub)" <gi...@apache.org>.
tabmatfournier commented on PR #10456:
URL: https://github.com/apache/iceberg/pull/10456#issuecomment-2153110975

   This should be gated by a config flag, so the user can control behavior.  For some users, a missing column may represent a bad message / something going wrong, and they may want to fail instead of modifying their table.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

Posted by "fqaiser94 (via GitHub)" <gi...@apache.org>.
fqaiser94 closed pull request #10456: Kafka-connect: Make required columns optional if missing from record
URL: https://github.com/apache/iceberg/pull/10456


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

Posted by "fqaiser94 (via GitHub)" <gi...@apache.org>.
fqaiser94 commented on code in PR #10456:
URL: https://github.com/apache/iceberg/pull/10456#discussion_r1629982369


##########
kafka-connect/kafka-connect/src/test/java/org/apache/iceberg/connect/data/RecordConverterTest.java:
##########
@@ -859,6 +859,107 @@ public void testEvolveTypeDetectionStructNested() {
     assertThat(updateMap.get("st.ff").type()).isInstanceOf(DoubleType.class);
   }
 
+  @Test
+  public void testDeletedColumnDetectionStruct() {
+    org.apache.iceberg.Schema tableSchema =
+        new org.apache.iceberg.Schema(
+            NestedField.required(1, "i", IntegerType.get()),
+            NestedField.required(2, "j", IntegerType.get()),
+            NestedField.optional(3, "k", IntegerType.get()));
+
+    Table table = mock(Table.class);
+    when(table.schema()).thenReturn(tableSchema);
+    RecordConverter converter = new RecordConverter(table, config);
+
+    Schema connectSchema = SchemaBuilder.struct().field("i", Schema.INT32_SCHEMA);
+    Struct data = new Struct(connectSchema).put("i", 1);
+    SchemaUpdate.Consumer consumer = new SchemaUpdate.Consumer();
+    converter.convert(data, consumer);
+    Collection<SchemaUpdate.MakeOptional> makeOptionals = consumer.makeOptionals();
+
+    assertThat(makeOptionals).hasSize(1);
+    assertThat(makeOptionals.iterator().next().name()).isEqualTo("j");
+  }

Review Comment:
   @bryanck while investigating a related [issue](https://github.com/tabular-io/iceberg-kafka-connect/issues/261) reported by a user of the original tabular connector, it occurred to me that maybe we should mark columns missing from the record as optional in the table. 
   
   Currently, we only evolve a field to optional if the field is explicitly marked as optional in the kafka-connect-schema. But for some serialization/deserialization processes, it's possible that the optional fields might not be included in the kafka-connect-schema at all for records missing that field. 
   
   Currently (i.e. without this change) the connector will simply throw an exception at the `IcebergWriter.write` stage (when it tries to write a null value into a non-null field) and be stuck until someone manually fixes the table schema outside of kafka-connect. 
   
   Not sure if this was an explicit design decision on your part or not but wanted to raise it up for discussion regardless. 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

Posted by "fqaiser94 (via GitHub)" <gi...@apache.org>.
fqaiser94 commented on code in PR #10456:
URL: https://github.com/apache/iceberg/pull/10456#discussion_r1629982369


##########
kafka-connect/kafka-connect/src/test/java/org/apache/iceberg/connect/data/RecordConverterTest.java:
##########
@@ -859,6 +859,107 @@ public void testEvolveTypeDetectionStructNested() {
     assertThat(updateMap.get("st.ff").type()).isInstanceOf(DoubleType.class);
   }
 
+  @Test
+  public void testDeletedColumnDetectionStruct() {
+    org.apache.iceberg.Schema tableSchema =
+        new org.apache.iceberg.Schema(
+            NestedField.required(1, "i", IntegerType.get()),
+            NestedField.required(2, "j", IntegerType.get()),
+            NestedField.optional(3, "k", IntegerType.get()));
+
+    Table table = mock(Table.class);
+    when(table.schema()).thenReturn(tableSchema);
+    RecordConverter converter = new RecordConverter(table, config);
+
+    Schema connectSchema = SchemaBuilder.struct().field("i", Schema.INT32_SCHEMA);
+    Struct data = new Struct(connectSchema).put("i", 1);
+    SchemaUpdate.Consumer consumer = new SchemaUpdate.Consumer();
+    converter.convert(data, consumer);
+    Collection<SchemaUpdate.MakeOptional> makeOptionals = consumer.makeOptionals();
+
+    assertThat(makeOptionals).hasSize(1);
+    assertThat(makeOptionals.iterator().next().name()).isEqualTo("j");
+  }

Review Comment:
   @bryanck while investigating a related [issue](https://github.com/tabular-io/iceberg-kafka-connect/issues/261) reported by a user of the original tabular connector, it occurred to me that maybe we should mark columns missing from the record as optional in the table. 
   
   Currently, we only evolve a field to optional if the field is explicitly marked as optional in the kafka-connect-schema. 
   
   But for some serialization/deserialization processes, it's possible that the optional fields might not be included in the kafka-connect-schema at all for records missing that field. For such records, we currently (i.e. without this change) will throw an exception at the `IcebergWriter.write` stage (when it tries to write a null value into a non-null field) and be stuck until someone manually fixes the table schema outside of kafka-connect. 
   
   Not sure if this was an explicit design decision on your part or not but wanted to raise it up for discussion regardless. 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Kafka-connect: Make required columns optional if missing from record [iceberg]

Posted by "bryanck (via GitHub)" <gi...@apache.org>.
bryanck commented on PR #10456:
URL: https://github.com/apache/iceberg/pull/10456#issuecomment-2417596688

   I'm somewhat reluctant to add this feature, as a user can alter the table schema themselves if needed. We follow that rationale w/ drops also, the user must drop the column themselves.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org