Skip to content

Commit 076ea68

Browse files
committed
refactor to make the avro schema more readable
1 parent 1493d0d commit 076ea68

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

hudi/src/main/scala/org/apache/spark/sql/delta/hudi/HudiSchemaUtils.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ object HudiSchemaUtils extends DeltaLogging {
3434
* corresponding Avro type.
3535
*/
3636
def transform[E <: DataType](elem: E, isNullable: Boolean, currentPath: String): Schema =
37-
elem match {
37+
elem match {
3838
case StructType(fields) =>
3939

4040
val avroFields: util.List[Schema.Field] = fields.map(f =>
4141
new Schema.Field(
4242
f.name,
43-
transform(f.dataType, f.nullable,
44-
if (currentPath.isEmpty) f.name else s"$currentPath.${f.name}"),
43+
transform(f.dataType, f.nullable, s"$currentPath.${f.name}"),
4544
f.getComment().orNull)).toList.asJava
4645
finalizeSchema(
47-
Schema.createRecord(elem.typeName, null, currentPath, false, avroFields),
46+
Schema.createRecord(currentPath, null, null, false, avroFields),
4847
isNullable)
4948
// TODO: Add List and Map support: https://github.com/delta-io/delta/issues/2738
5049
case ArrayType(elementType, containsNull) =>
@@ -59,7 +58,7 @@ object HudiSchemaUtils extends DeltaLogging {
5958
throw new UnsupportedOperationException(s"Cannot convert Delta type $other to Hudi")
6059
}
6160

62-
transform(deltaSchema, false, "")
61+
transform(deltaSchema, false, "root")
6362
}
6463

6564
private def finalizeSchema(targetSchema: Schema, isNullable: Boolean): Schema = {

0 commit comments

Comments
 (0)