當前位置: 首頁>>代碼示例>>Java>>正文


Java Field類代碼示例

本文整理匯總了Java中org.apache.avro.Schema.Field的典型用法代碼示例。如果您正苦於以下問題:Java Field類的具體用法?Java Field怎麽用?Java Field使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Field類屬於org.apache.avro.Schema包,在下文中一共展示了Field類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findField

import org.apache.avro.Schema.Field; //導入依賴的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.Field; //導入依賴的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

示例3: testOverrideTypeMapping

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testOverrideTypeMapping() throws IOException {
  String [] types = { "INT" };
  String [] vals = { "10" };
  createTableWithColTypes(types, vals);

  String [] extraArgs = { "--map-column-java", "DATA_COL0=String"};
  runImport(getOutputArgv(true, extraArgs));

  Schema schema = getSchema();
  assertEquals(Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());
  checkField(fields.get(0), "DATA_COL0", Type.STRING);

  DatasetReader<GenericRecord> reader = getReader();
  try {
    assertTrue(reader.hasNext());
    GenericRecord record1 = reader.next();
    assertEquals("DATA_COL0", "10", record1.get("DATA_COL0"));
    assertFalse(reader.hasNext());
  } finally {
    reader.close();
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:25,代碼來源:TestParquetImport.java

示例4: testFirstUnderscoreInColumnName

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testFirstUnderscoreInColumnName() throws IOException {
  String [] names = { "_NAME" };
  String [] types = { "INT" };
  String [] vals = { "1987" };
  createTableWithColTypesAndNames(names, types, vals);

  runImport(getOutputArgv(true, null));

  Schema schema = getSchema();
  assertEquals(Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());
  checkField(fields.get(0), "__NAME", Type.INT);

  DatasetReader<GenericRecord> reader = getReader();
  try {
    assertTrue(reader.hasNext());
    GenericRecord record1 = reader.next();
    assertEquals("__NAME", 1987, record1.get("__NAME"));
    assertFalse(reader.hasNext());
  } finally {
    reader.close();
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:25,代碼來源:TestParquetImport.java

示例5: testNonIdentCharactersInColumnName

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testNonIdentCharactersInColumnName() throws IOException {
  String [] names = { "test_p-a+r/quet" };
  String [] types = { "INT" };
  String [] vals = { "2015" };
  createTableWithColTypesAndNames(names, types, vals);

  runImport(getOutputArgv(true, null));

  Schema schema = getSchema();
  assertEquals(Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());
  checkField(fields.get(0), "TEST_P_A_R_QUET", Type.INT);

  DatasetReader<GenericRecord> reader = getReader();
  try {
    assertTrue(reader.hasNext());
    GenericRecord record1 = reader.next();
    assertEquals("TEST_P_A_R_QUET", 2015, record1.get("TEST_P_A_R_QUET"));
    assertFalse(reader.hasNext());
  } finally {
    reader.close();
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:25,代碼來源:TestParquetImport.java

示例6: testFirstUnderscoreInColumnName

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testFirstUnderscoreInColumnName() throws IOException {
  String [] names = { "_NAME" };
  String [] types = { "INT" };
  String [] vals = { "1987" };
  createTableWithColTypesAndNames(names, types, vals);

  runImport(getOutputArgv(true, null));

  Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
  DataFileReader<GenericRecord> reader = read(outputFile);
  Schema schema = reader.getSchema();
  assertEquals(Schema.Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());

  checkField(fields.get(0), "__NAME", Type.INT);

  GenericRecord record1 = reader.next();
  assertEquals("__NAME", 1987, record1.get("__NAME"));
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:21,代碼來源:TestAvroImport.java

示例7: testNonstandardCharactersInColumnName

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testNonstandardCharactersInColumnName() throws IOException {
  String [] names = { "avro\uC3A11" };
  String [] types = { "INT" };
  String [] vals = { "1987" };
  createTableWithColTypesAndNames(names, types, vals);

  runImport(getOutputArgv(true, null));

  Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
  DataFileReader<GenericRecord> reader = read(outputFile);
  Schema schema = reader.getSchema();
  assertEquals(Schema.Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());

  checkField(fields.get(0), "AVRO1", Type.INT);

  GenericRecord record1 = reader.next();
  assertEquals("AVRO1", 1987, record1.get("AVRO1"));
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:21,代碼來源:TestAvroImport.java

示例8: testNonIdentCharactersInColumnName

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public void testNonIdentCharactersInColumnName() throws IOException {
  String [] names = { "test_a-v+r/o" };
  String [] types = { "INT" };
  String [] vals = { "2015" };
  createTableWithColTypesAndNames(names, types, vals);

  runImport(getOutputArgv(true, null));

  Path outputFile = new Path(getTablePath(), "part-m-00000.avro");
  DataFileReader<GenericRecord> reader = read(outputFile);
  Schema schema = reader.getSchema();
  assertEquals(Schema.Type.RECORD, schema.getType());
  List<Field> fields = schema.getFields();
  assertEquals(types.length, fields.size());

  checkField(fields.get(0), "TEST_A_V_R_O", Type.INT);

  GenericRecord record1 = reader.next();
  assertEquals("TEST_A_V_R_O", 2015, record1.get("TEST_A_V_R_O"));
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:21,代碼來源:TestAvroImport.java

示例9: parseField

import org.apache.avro.Schema.Field; //導入依賴的package包/類
protected FieldNode parseField(Field field, AvroNode parentNode) {

		FieldNode fieldNode = new FieldNode(context);
		// init attributes
		fieldAttributeInitializer.setField(field);
		fieldNode.init(fieldAttributeInitializer);
		linkNodes(parentNode, fieldNode);
		registerNode(fieldNode);
		
		// type
		Schema fieldSchema = field.schema();
		if (!PrimitiveType.isPrimitive(fieldSchema)) {
			// add child node representing the complex type
			parseSchema(fieldSchema, fieldNode);			
		}		
		
		return fieldNode;
	}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:19,代碼來源:AvroSchemaParserImpl.java

示例10: generateAppropriateWrapper

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public static String generateAppropriateWrapper(Schema schema, Field field) {
  if (DIRTY_BYTES_FIELD_NAME.equals(field.name())) {
    return "java.nio.ByteBuffer.wrap(new byte["
      + getNumberOfBytesNeededForDirtyBits(schema) + "])";
  } else {
    switch (field.schema().getType()) {
    case RECORD:
      return field.schema().getName()+".newBuilder().build()";
    case MAP:
      return "new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)defaultValue(fields()["+field.pos()+"]))";
    case ARRAY:
      return "new org.apache.gora.persistency.impl.DirtyListWrapper((java.util.List)defaultValue(fields()["+field.pos()+"]))";
    default:
      return "defaultValue(fields()["+field.pos()+"])";
    }
  }
  
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:19,代碼來源:GoraCompiler.java

示例11: getPersistent

import org.apache.avro.Schema.Field; //導入依賴的package包/類
/**
 * Returns a clone with exactly the requested fields shallowly copied
 */
private static<T extends Persistent> T getPersistent(T obj, String[] fields) {
  List<Field> otherFields = obj.getSchema().getFields();
  String[] otherFieldStrings = new String[otherFields.size()];
  for(int i = 0; i<otherFields.size(); i++ ){
    otherFieldStrings[i] = otherFields.get(i).name();
  }
  if(Arrays.equals(fields, otherFieldStrings)) { 
    return obj;
  }
  T newObj = AvroUtils.deepClonePersistent(obj);
  for (Field otherField : otherFields) {
    int index = otherField.pos();
    newObj.put(index, obj.get(index));
  }
  return newObj;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:20,代碼來源:MemStore.java

示例12: checkIfMutableFieldAndDirty

import org.apache.avro.Schema.Field; //導入依賴的package包/類
private boolean checkIfMutableFieldAndDirty(Field field) {
  if (field.pos() == 0)
    return false;
  switch (field.schema().getType()) {
  case RECORD:
  case MAP:
  case ARRAY:
    Object value = get(field.pos());
    return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
  case UNION:
    value = get(field.pos());
    return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
  default:
    break;
  }
  return false;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:18,代碼來源:PersistentBase.java

示例13: getFields

import org.apache.avro.Schema.Field; //導入依賴的package包/類
protected String[] getFields() {
  List<Field> schemaFields = beanFactory.getCachedPersistent().getSchema().getFields();
  
  List<Field> list = new ArrayList<>();
  for (Field field : schemaFields) {
    if (!Persistent.DIRTY_BYTES_FIELD_NAME.equalsIgnoreCase(field.name())) {
      list.add(field);
    }
  }
  schemaFields = list;
  
  String[] fieldNames = new String[schemaFields.size()];
  for(int i = 0; i<fieldNames.length; i++ ){
    fieldNames[i] = schemaFields.get(i).name();
  }
  
  return fieldNames;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:19,代碼來源:DataStoreBase.java

示例14: getFields

import org.apache.avro.Schema.Field; //導入依賴的package包/類
public static String[] getFields(List<Field> schemaFields) {
  
  List<Field> list = new ArrayList<>();
  for (Field field : schemaFields) {
    if (!Persistent.DIRTY_BYTES_FIELD_NAME.equalsIgnoreCase(field.name())) {
      list.add(field);
    }
  }
  schemaFields = list;
  
  String[] fieldNames = new String[schemaFields.size()];
  for(int i = 0; i<fieldNames.length; i++ ){
    fieldNames[i] = schemaFields.get(i).name();
  }
  
  return fieldNames;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:18,代碼來源:DataStoreTestUtil.java

示例15: newInstance

import org.apache.avro.Schema.Field; //導入依賴的package包/類
/**
 * Creates a new Persistent instance with the values in 'result' for the fields listed.
 * @param result result form a HTable#get()
 * @param fields List of fields queried, or null for all
 * @return A new instance with default values for not listed fields
 *         null if 'result' is null.
 * @throws IOException
 */
public T newInstance(Result result, String[] fields)
throws IOException {
  if(result == null || result.isEmpty())
    return null;

  T persistent = newPersistent();
  for (String f : fields) {
    HBaseColumn col = mapping.getColumn(f);
    if (col == null) {
      throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
          "Wrong gora-hbase-mapping.xml?");
    }
    Field field = fieldMap.get(f);
    Schema fieldSchema = field.schema();
    setField(result,persistent, col, field, fieldSchema);
  }
  persistent.clearDirty();
  return persistent;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:28,代碼來源:HBaseStore.java


注:本文中的org.apache.avro.Schema.Field類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。