Reputation: 735
Avro is not generating UUID class in code for fields no mater what I tried.
Versions: 1.8.2 & 1.9.1
I tried to generate UUID with such schema:
"type": "record",
"name": "RecordWithUUID",
"namespace": "avro",
"fields": [
{
"name": "uuid",
"type": {
"type": "string",
"logicalType": "uuid"
}
}
]
}
This is the class from Avro project test class TestReflectLogicalTypes
::RecordWithUUID
So, in short this is example of schema that Avro uses to test their code functionality and I expected that it should work.
I run like this to get java code from my scheme:
java -jar avro-tools-1.8.2.jar compile schema my_scheme.avsc .
java -jar avro-tools-1.9.1.jar compile schema my_scheme.avsc .
The initial class code from Avro is like this:
class RecordWithUUID {
UUID uuid; // <- UUID (!!!)
@Override
public int hashCode() {
return uuid.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof RecordWithUUID)) {
return false;
}
RecordWithUUID that = (RecordWithUUID) obj;
return this.uuid.equals(that.uuid);
}
}
Here is code that I got after generating:
1.8.2 avro-tools from command line
..
@SuppressWarnings("all")
@org.apache.avro.specific.AvroGenerated
public class RecordWithUUID extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
private static final long serialVersionUID = 9147582668665082277L;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RecordWithUUID\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"uuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}}]}");
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
..
@Deprecated public java.lang.CharSequence uuid; //<- NO UUID
..
1.9.1 avro-tools from command line
..
@org.apache.avro.specific.AvroGenerated
public class RecordWithUUID extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
private static final long serialVersionUID = 9147582668665082277L;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RecordWithUUID\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"uuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}}]}");
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
..
private java.lang.CharSequence uuid; //<- NO UUID
..
maven plugin for avro 1.8.2/1.9.1
..
@org.apache.avro.specific.AvroGenerated
public class RecordWithUUID extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
private static final long serialVersionUID = 9147582668665082277L;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RecordWithUUID\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"uuid\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\",\"logicalType\":\"uuid\"}}]}");
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
..
private java.lang.String uuid;//<- NO UUID
..
So, is it a bug or I'm doing something wrong ?
Upvotes: 2
Views: 1601
Reputation: 1887
Try 1.10.0-SNAPSHOT, I have it working there (after experiencing the same issues as you with the other versions)
Upvotes: 1