Closed steven-aerts closed 6 years ago
Merging #256 into branch-4.0 will not change coverage. The diff coverage is
100%
.
@@ Coverage Diff @@
## branch-4.0 #256 +/- ##
===========================================
Coverage 90.71% 90.71%
===========================================
Files 5 5
Lines 334 334
Branches 50 50
===========================================
Hits 303 303
Misses 31 31
Hi @steven-aerts , is this patch compatible with AVRO 1.7?
Yes it is, as GenericFixed is much older than 1.8.
Btw spark-avro is still using avro 1.7.6 and everything still works after this patch.
I take a quick try with py avro 1.8.2. And spark-avro can load the avro with fixed field. Can you share more details about how the read fails?
When you take the following schema:
{
"type": "record",
"name": "Record",
"namespace": "org.example.bug",
"fields": [{"name": "macAddress", "type": {"type": "fixed", "size": 6, "name":"MacAddress" }}]
}
And you generate the java code for it:
java -jar /usr/localdisk/software/avro-tools/avro-tools-1.8.0.jar schema compile record.avsc src/main/java
Then you can write a test like this:
@Test
public void testBug256() {
Record record = Record.newBuilder().setMacAddress(new MacAddress(new byte[7])).build();
Schema schema = Record.getClassSchema();
StructType strucType = (StructType) SchemaConverters$.MODULE$.toSqlType(schema).dataType();
GenericRow test = (GenericRow) SchemaConverters$.MODULE$.createConverterToSQL(schema, strucType).apply(record);
}
Which will fail with the stacktrace above. When you use the 1.7 code generator, it will work.
Thanks, merge to master/branch-4.0
Fixed types generated with the 1.8 avro code generator do not extend from
GenericData.Fixed
anymore. This triggers aClassCastException
when converting an object from such a class to aGenericRow
.This problem is solved by using the GenericFixed base type.