Skip to content

Instantly share code, notes, and snippets.

@dalelane
dalelane / schema14.avsc
Created July 20, 2019 22:33
Example of an Avro schema - used in https://dalelane.co.uk/blog/?p=3781
{
"type": "record",
"namespace": "co.uk.dalelane",
"name": "Type14",
"fields": [
{
"name": "something",
"type": "string"
}
]
Type13 myThing = new Type13();
myThing.setMyWord("diabolical");
LogicalTypes.register(WordsThatStartWithD.PROPERTY_NAME,
new WordsThatStartWithD.TypeFactory());
import org.apache.avro.LogicalType;
import org.apache.avro.LogicalTypes.LogicalTypeFactory;
import org.apache.avro.Schema;
public class WordsThatStartWithD extends LogicalType {
public static final String PROPERTY_NAME = "words-that-start-with-D";
private static final String INVALID_TYPE = "Logical type 'words-that-start-with-D' must be strings";
@dalelane
dalelane / schema13.avsc
Last active July 20, 2019 22:34
Example of an Avro schema - used in https://dalelane.co.uk/blog/?p=3781
{
"type": "record",
"namespace": "co.uk.dalelane",
"name": "Type13",
"fields": [
{
"name": "myWord",
"type": {
"type": "string",
"name": "WordThatStartsWithD",
Type12 myThing = new Type12();
myThing.setPreciselyWhenItHappened(System.currentTimeMillis());
@dalelane
dalelane / schema12.avsc
Last active July 20, 2019 22:35
Example of an Avro schema - used in https://dalelane.co.uk/blog/?p=3781
{
"type": "record",
"name": "Type12",
"namespace": "co.uk.dalelane",
"fields": [
{
"name": "preciselyWhenItHappened",
"type": "long",
"logicalType": "time-millis"
}
Type10 myThing = new Type10();
myThing.setWhenItHappened(LocalDate.now().toEpochDay());
@dalelane
dalelane / schema10.avsc
Last active July 20, 2019 22:35
Example of an Avro schema - used in https://dalelane.co.uk/blog/?p=3781
{
"type": "record",
"name": "Type10",
"namespace": "co.uk.dalelane",
"fields": [
{
"name": "whenItHappened",
"type": "long",
"logicalType": "date"
}
Type9 myThingA = new Type9();
myThingA.setRequiredString("Hello");
myThingA.setOptionalString("World");
Type9 myThingB = new Type9();
myThingB.setRequiredString("Hello");