[ https://issues.apache.org/jira/browse/KAFKA-17029?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17860799#comment-17860799 ]
Ksolves commented on KAFKA-17029: --------------------------------- For all the implementation classes i.e. FakeSchema, ConnectSchema, SchemaBuilder, the fields() method will throw DataException if the type is not STRUCT. Proposed Solutions: 1. Remove Type Check from Implementations: Remove the check if `type != Type.STRUCT` from all implementations of the fields() method in FakeSchema, ConnectSchema, SchemaBuilder, etc. This would involve modifying existing behavior to ensure that fields are handled appropriately regardless of schema type. 2. Introduce a New Method in the Schema Interface: Introduce a new method in the Schema interface (e.g., fieldsIgnoreTypeCheck()) that does not perform the `type != Type.STRUCT` check and simply returns the fields. Update the SetSchemaMetadata#apply the method to use this new method (e.g., schema.fieldsIgnoreTypeCheck()), ensuring that the SMT can handle schemas without throwing a DataException. Let me know your thoughts. > SetSchemaMetadata smt throws DataException when avro schema is primitive type > ----------------------------------------------------------------------------- > > Key: KAFKA-17029 > URL: https://issues.apache.org/jira/browse/KAFKA-17029 > Project: Kafka > Issue Type: Bug > Reporter: Mark McDonald > Priority: Minor > > The SetSchemaMetadata smt can be used to set the schema name and version on > connect records. However, if the connect record is an Avro primitive type, > the smt thows a DataException. The reason for this is because there is a call > to the Schema [fields() > method|https://kafka.apache.org/20/javadoc/org/apache/kafka/connect/data/Schema.html#fields--]. > This smt should be able to handle the case when the schema is not a struct. > [This is > where|https://github.com/apache/kafka/blob/42058462ac9ef65e0cad4240358bbb5db9cebcd4/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/SetSchemaMetadata.java#L90] > the DataException is encountered. > > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)