Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object AvroConversionHelper {
case (struct: StructType, RECORD) =>
val length = struct.fields.length
val converters = new Array[AnyRef => AnyRef](length)
val avroFieldIndexes = new Array[Int](length)
val avroFieldNames = new Array[String](length)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question : Does this work for nested schemas where same name is used in different hierarchy ? For example : "order.rec.rec" (I am just making this up) but wanted to make sure if there are any chances of ambiguity in field resolution that can arise ? Can you add some test-cases to verify this would work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will try to write some tests

var i = 0
while (i < length) {
val sqlField = struct.fields(i)
Expand All @@ -145,7 +145,7 @@ object AvroConversionHelper {
val converter = createConverter(avroField.schema(), sqlField.dataType,
path :+ sqlField.name)
converters(i) = converter
avroFieldIndexes(i) = avroField.pos()
avroFieldNames(i) = avroField.name()
} else if (!sqlField.nullable) {
throw new IncompatibleSchemaException(
s"Cannot find non-nullable field ${sqlField.name} at path ${path.mkString(".")} " +
Expand All @@ -167,7 +167,7 @@ object AvroConversionHelper {
while (i < converters.length) {
if (converters(i) != null) {
val converter = converters(i)
result(i) = converter(record.get(avroFieldIndexes(i)))
result(i) = converter(record.get(avroFieldNames(i)))
}
i += 1
}
Expand Down