HeartSaVioR commented on code in PR #49277: URL: https://github.com/apache/spark/pull/49277#discussion_r1915918525
########## sql/core/src/main/scala/org/apache/spark/sql/avro/SchemaConverters.scala: ########## @@ -374,67 +374,29 @@ object SchemaConverters extends Logging { } } - 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 => - field.dataType match { - case nested: StructType => - // For nested structs, recursively create the default structure - defaultMap.put(field.name, createNestedDefault(nested)) - case _ => - // For leaf fields, use null - defaultMap.put(field.name, null) - } + private def createDefaultStruct(st: StructType): java.util.HashMap[String, Any] = { + val defaultMap = new java.util.HashMap[String, Any]() + st.fields.foreach { field => + field.dataType match { + case nested: StructType => + defaultMap.put(field.name, createDefaultStruct(nested)) + case _ => + defaultMap.put(field.name, null) } - defaultMap - } - - dataType match { - // Basic types - case BooleanType => null - case ByteType | ShortType | IntegerType => null - case LongType => null - case FloatType => null - case DoubleType => null - case StringType => null - case BinaryType => null - - // Complex types - case ArrayType(_, _) => new java.util.ArrayList[Any]() - case MapType(StringType, _, _) => new java.util.HashMap[String, Any]() - case st: StructType => createNestedDefault(st) - - // Special types - case _: DecimalType => java.nio.ByteBuffer.allocate(0) - case DateType => null - case TimestampType => null - case TimestampNTZType => null - case NullType => null - case _ => null } + defaultMap } def toAvroTypeWithDefaults( Review Comment: No, I'm not only concerned about nullable. If you revisit callers of this method, I don't see any parameter except catalystType to be used, and catalystType is always StructType. (I can be corrected.) Shall we distinguish the method we are exposing to caller vs the method to recursively resolve? -- 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