本文整理汇总了Java中org.apache.avro.Schema.getField方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.getField方法的具体用法?Java Schema.getField怎么用?Java Schema.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.Schema
的用法示例。
在下文中一共展示了Schema.getField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findField
import org.apache.avro.Schema; //导入方法依赖的package包/类
private static Field findField(Schema schema, String name) {
if (schema.getField(name) != null) {
return schema.getField(name);
}
Field foundField = null;
for (Field field : schema.getFields()) {
Schema fieldSchema = field.schema();
if (Type.RECORD.equals(fieldSchema.getType())) {
foundField = findField(fieldSchema, name);
} else if (Type.ARRAY.equals(fieldSchema.getType())) {
foundField = findField(fieldSchema.getElementType(), name);
} else if (Type.MAP.equals(fieldSchema.getType())) {
foundField = findField(fieldSchema.getValueType(), name);
}
if (foundField != null) {
return foundField;
}
}
return foundField;
}
示例2: lookupWriterField
import org.apache.avro.Schema; //导入方法依赖的package包/类
/**
* Identifies the writer field that corresponds to the specified reader field.
*
* <p> Matching includes reader name aliases. </p>
*
* @param writerSchema Schema of the record where to look for the writer field.
* @param readerField Reader field to identify the corresponding writer field of.
* @return the writer field, if any does correspond, or None.
*/
public static Field lookupWriterField(final Schema writerSchema, final Field readerField) {
assert (writerSchema.getType() == Type.RECORD);
final List<Field> writerFields = new ArrayList<Field>();
final Field direct = writerSchema.getField(readerField.name());
if (direct != null) {
writerFields.add(direct);
}
for (final String readerFieldAliasName : readerField.aliases()) {
final Field writerField = writerSchema.getField(readerFieldAliasName);
if (writerField != null) {
writerFields.add(writerField);
}
}
switch (writerFields.size()) {
case 0: return null;
case 1: return writerFields.get(0);
default: {
throw new AvroRuntimeException(String.format(
"Reader record field %s matches multiple fields in writer record schema %s",
readerField, writerSchema));
}
}
}