當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。