本文整理匯總了Java中org.apache.avro.Schema.Type.RECORD屬性的典型用法代碼示例。如果您正苦於以下問題:Java Type.RECORD屬性的具體用法?Java Type.RECORD怎麽用?Java Type.RECORD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.avro.Schema.Type
的用法示例。
在下文中一共展示了Type.RECORD屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUsedTypeFromUnion
private static Type getUsedTypeFromUnion(Object avroObjField) {
if (GenericRecord.class.isAssignableFrom(avroObjField.getClass())) {
return Type.RECORD;
} else if (Number.class.isAssignableFrom(avroObjField.getClass())) {
return Type.LONG;
} else if (Boolean.class.isAssignableFrom(avroObjField.getClass())) {
return Type.BOOLEAN;
} else if (String.class.isAssignableFrom(avroObjField.getClass())) {
return Type.STRING;
} else if (byte[].class.isAssignableFrom(avroObjField.getClass()) || ByteBuffer.class.isAssignableFrom(avroObjField.getClass())) {
return Type.BYTES;
} else if (Map.class.isAssignableFrom(avroObjField.getClass())) {
return Type.MAP;
} else if (List.class.isAssignableFrom(avroObjField.getClass())) {
return Type.ARRAY;
} else if (Enum.class.isAssignableFrom(avroObjField.getClass())) {
return Type.ENUM;
} else {
LOGGER.error("Used type of union is unknown.");
return null;
}
}
示例2: convertField
private static Field convertField(TableFieldSchema bigQueryField) {
Type avroType = BIG_QUERY_TO_AVRO_TYPES.get(bigQueryField.getType());
Schema elementSchema;
if (avroType == Type.RECORD) {
elementSchema = toGenericAvroSchema(bigQueryField.getName(), bigQueryField.getFields());
} else {
elementSchema = Schema.create(avroType);
}
Schema fieldSchema;
if (bigQueryField.getMode() == null || bigQueryField.getMode().equals("NULLABLE")) {
fieldSchema = Schema.createUnion(Schema.create(Type.NULL), elementSchema);
} else if (bigQueryField.getMode().equals("REQUIRED")) {
fieldSchema = elementSchema;
} else if (bigQueryField.getMode().equals("REPEATED")) {
fieldSchema = Schema.createArray(elementSchema);
} else {
throw new IllegalArgumentException(
String.format("Unknown BigQuery Field Mode: %s", bigQueryField.getMode()));
}
return new Field(
bigQueryField.getName(),
fieldSchema,
bigQueryField.getDescription(),
(Object) null /* Cast to avoid deprecated JsonNode constructor. */);
}
示例3: validate
public void validate(final Schema schema) {
if (schema.getType() != Type.RECORD)
throw new IllegalArgumentException("Must be type " + Type.RECORD);
nameCodec.validate(schema.getName());
if (schema.getFields().size() > FIELDS_MAX_COUNT)
throw new IllegalArgumentException("Only supports up to " + FIELDS_MAX_COUNT + " fields. Found " + schema.getFields().size());
for (final Field field : schema.getFields()) {
nameCodec.validate(field.name());
fieldCodec.validate(field.schema());
}
}
示例4: getRecordSchemaWithDirtySupport
private static Schema getRecordSchemaWithDirtySupport(Schema originalSchema, Map<Schema,Schema> queue) throws IOException {
if (originalSchema.getType() != Type.RECORD) {
throw new IOException("Gora only supports record schemas.");
}
List<Field> originalFields = originalSchema.getFields();
/* make sure the schema doesn't contain the field __g__dirty */
for (Field field : originalFields) {
if (GORA_RESERVED_NAMES.contains(field.name())) {
throw new IOException(
"Gora schemas cannot contain the field name " + field.name());
}
}
Schema newSchema = Schema.createRecord(originalSchema.getName(),
originalSchema.getDoc(), originalSchema.getNamespace(),
originalSchema.isError());
queue.put(originalSchema, newSchema);
List<Field> newFields = new ArrayList<>();
byte[] defaultDirtyBytesValue = new byte[getNumberOfBytesNeededForDirtyBits(originalSchema)];
Arrays.fill(defaultDirtyBytesValue, (byte) 0);
JsonNode defaultDirtyJsonValue = JsonNodeFactory.instance
.binaryNode(defaultDirtyBytesValue);
Field dirtyBits = new Field(DIRTY_BYTES_FIELD_NAME,
Schema.create(Type.BYTES),
"Bytes used to represent weather or not a field is dirty.",
defaultDirtyJsonValue);
newFields.add(dirtyBits);
for (Field originalField : originalFields) {
// recursively add dirty support
Field newField = new Field(originalField.name(),
getSchemaWithDirtySupport(originalField.schema(),queue),
originalField.doc(), originalField.defaultValue(),
originalField.order());
newFields.add(newField);
}
newSchema.setFields(newFields);
return newSchema;
}
示例5: getType
public static Type getType(Class<?> clazz) {
if (clazz.equals(Utf8.class)) {
return Type.STRING;
} else if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
return Type.BOOLEAN;
} else if (clazz.equals(ByteBuffer.class)) {
return Type.BYTES;
} else if (clazz.equals(Double.class) || clazz.equals(double.class)) {
return Type.DOUBLE;
} else if (clazz.equals(Float.class) || clazz.equals(float.class)) {
return Type.FLOAT;
} else if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
return Type.INT;
} else if (clazz.equals(Long.class) || clazz.equals(long.class)) {
return Type.LONG;
} else if (clazz.isAssignableFrom(List.class)) {
return Type.ARRAY;
} else if (clazz.isAssignableFrom(Map.class)) {
return Type.MAP;
} else if (clazz.equals(Persistent.class)) {
return Type.RECORD;
} else if (clazz.getSuperclass().equals(SpecificFixed.class)) {
return Type.FIXED;
} else {
return null;
}
}
示例6: getClass
public static Class<?> getClass(Type type) {
if (type == Type.STRING) {
return Utf8.class;
} else if (type == Type.BOOLEAN) {
return Boolean.class;
} else if (type == Type.BYTES) {
return ByteBuffer.class;
} else if (type == Type.DOUBLE) {
return Double.class;
} else if (type == Type.FLOAT) {
return Float.class;
} else if (type == Type.INT) {
return Integer.class;
} else if (type == Type.LONG) {
return Long.class;
} else if (type == Type.ARRAY) {
return List.class;
} else if (type == Type.MAP) {
return Map.class;
} else if (type == Type.RECORD) {
return Persistent.class;
} else if (type == Type.FIXED) {
// return SpecificFixed.class;
return null;
} else {
return null;
}
}
示例7: render
private void render(Schema sc, String parent, boolean isNullable) {
String childId = newIdFor(parent, sc.getName());
startNewLine();
appendIds(childId, parent);
append("type", typeFor(sc, isNullable), true);
append("text", labelFor(sc), false);
appendDoc(sc.getDoc());
endLine();
if (showConstraints) showConstraints(sc, childId);
if (showMetrics) showMetrics(sc, childId);
incrementDepth();
if (sc.getType() == Type.RECORD) {
for (Field fld : sc.getFields()) {
render(fld, childId);
}
}
if (sc.getType() == Type.ARRAY) {
render(sc.getElementType(), childId, false);
}
if (sc.getType() == Type.UNION) {
System.out.println("####!!!!!####");
}
decrementDepth();
}
示例8: isRecordType
public static boolean isRecordType(Schema schema) {
return schema != null && schema.getType() == Type.RECORD;
}