ericm-db commented on code in PR #49277: URL: https://github.com/apache/spark/pull/49277#discussion_r1913906523
########## sql/core/src/main/scala/org/apache/spark/sql/avro/SchemaConverters.scala: ########## @@ -372,6 +373,178 @@ object SchemaConverters extends Logging { schema } } + + /** + * Creates default values for Spark SQL data types when converting to Avro. + * This ensures fields have appropriate defaults during schema evolution. + * + * This method recursively processes Spark SQL data types and generates corresponding + * default values that are compatible with Avro schema specifications. It handles + * both primitive types (like Boolean, Integer) and complex types (Arrays, Maps, Structs). + * + * @param dataType The Spark SQL DataType to create a default value for + * @return A default value appropriate for the given data type that's compatible with Avro + */ + private def getDefaultValue(dataType: DataType): Any = { + def createNestedDefault(st: StructType): java.util.HashMap[String, Any] = { + val defaultMap = new java.util.HashMap[String, Any]() + st.fields.foreach { field => + defaultMap.put(field.name, getDefaultValue(field.dataType)) + } + defaultMap + } + + dataType match { + // Basic types + case BooleanType => false + case ByteType | ShortType | IntegerType => 0 + case LongType => 0L + case FloatType => 0.0f Review Comment: Okay, updated the SchemaConverters method - should be fine now. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org