Last active
July 20, 2019 22:37
-
-
Save dalelane/35416f3f05dfed135d437a029afbee41 to your computer and use it in GitHub Desktop.
Sample code used in https://dalelane.co.uk/blog/?p=3781
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
public WordsThatStartWithD() { | |
super(PROPERTY_NAME); | |
} | |
@Override | |
public void validate(Schema schema) { | |
super.validate(schema); | |
if (schema.getType() != Schema.Type.STRING) { | |
throw new IllegalArgumentException(INVALID_TYPE); | |
} | |
} | |
public static class TypeFactory implements LogicalTypeFactory { | |
private WordsThatStartWithD type = new WordsThatStartWithD(); | |
@Override | |
public LogicalType fromSchema(Schema schema) { | |
return type; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment