Skip to content

Instantly share code, notes, and snippets.

@dalelane
Last active July 20, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalelane/35416f3f05dfed135d437a029afbee41 to your computer and use it in GitHub Desktop.
Save dalelane/35416f3f05dfed135d437a029afbee41 to your computer and use it in GitHub Desktop.
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