当前位置: 首页>>代码示例>>Java>>正文


Java Schema.getField方法代码示例

本文整理汇总了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;
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:25,代码来源:ExtendedJsonDecoder.java

示例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));
    }
  }
}
 
开发者ID:HotelsDotCom,项目名称:avro-compatibility,代码行数:33,代码来源:SchemaCompatibility.java


注:本文中的org.apache.avro.Schema.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。