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


Java Schema.getFields方法代码示例

本文整理汇总了Java中org.apache.avro.Schema.getFields方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.getFields方法的具体用法?Java Schema.getFields怎么用?Java Schema.getFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.avro.Schema的用法示例。


在下文中一共展示了Schema.getFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testNonIdentCharactersInColumnName

import org.apache.avro.Schema; //导入方法依赖的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

示例3: convertAvroRecordUseBeforeMap

import org.apache.avro.Schema; //导入方法依赖的package包/类
public static <T extends Object> PairWrapper<String, Object> convertAvroRecordUseBeforeMap(GenericRecord record, Set<T> noorderKeys) {
    Schema schema = record.getSchema();
    List<Schema.Field> fields = schema.getFields();
    PairWrapper<String, Object> wrapper = new PairWrapper<>();

    for (Schema.Field field : fields) {
        String key = field.name();
        Object value = record.get(key);
        // 分离存储是否关心顺序的key-value
        if (noorderKeys.contains(field.name())) {
            wrapper.addProperties(key, value);
        }
    }

    GenericRecord before = getFromRecord(MessageBodyKey.BEFORE, record);

    Map<String, Object> beforeMap = convert2map(before);

    for (Map.Entry<String, Object> entry : beforeMap.entrySet()) {
        if(!entry.getKey().endsWith(MessageBodyKey.IS_MISSING_SUFFIX)) {
            wrapper.addPair(new Pair<>(entry.getKey(), CharSequence.class.isInstance(entry.getValue())?entry.getValue().toString():entry.getValue()));
        }
    }

    return wrapper;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:27,代码来源:BoltCommandHandlerHelper.java

示例4: testNonstandardCharactersInColumnName

import org.apache.avro.Schema; //导入方法依赖的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

示例5: testFirstUnderscoreInColumnName

import org.apache.avro.Schema; //导入方法依赖的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

示例6: testFirstUnderscoreInColumnName

import org.apache.avro.Schema; //导入方法依赖的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

示例7: testNonIdentCharactersInColumnName

import org.apache.avro.Schema; //导入方法依赖的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

示例8: createGenericRecordWithSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
private static GenericRecord createGenericRecordWithSchema(Schema schema, GenericRecord avrObj){
    GenericRecordBuilder builder = new GenericRecordBuilder(schema);
    for (Schema.Field field : schema.getFields()){
        builder.set(field, avrObj.get(field.name()));
    }
    return builder.build();
}
 
开发者ID:atlascon,项目名称:avro-diff,代码行数:8,代码来源:AvroDiff.java

示例9: read

import org.apache.avro.Schema; //导入方法依赖的package包/类
@Override
public Option<Model> read(Class<?> cls, Map<String, String> typeMap) {
  Schema schema = getSchema(cls);
  if (schema == null) {
    return Option.empty();
  }

  LinkedHashMap<String, ModelProperty> properties = new LinkedHashMap<>();
  for (Schema.Field field : schema.getFields()) {
    ModelProperty property = parseField(field);
    if (property == null) {
      LOGGER.debug(
          "Omitted field {} of schema {} from swagger docs", field.name(), schema.getName());
    } else {
      properties.update(getFieldName(field), property);
    }
  }

  return Option.apply(
      new Model(
          toName(cls),
          toName(cls),
          cls.getName(),
          properties,
          toDescriptionOpt(cls),
          Option.<String>empty(),
          Option.<String>empty(),
          JavaConversions.asScalaBuffer(Collections.<String>emptyList()).toList()));
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:30,代码来源:SwaggerAvroModelConverter.java

示例10: convertAvroRecord

import org.apache.avro.Schema; //导入方法依赖的package包/类
public static <T extends Object> PairWrapper<String, Object> convertAvroRecord(GenericRecord record, Set<T> noorderKeys) {
    Schema schema = record.getSchema();
    List<Schema.Field> fields = schema.getFields();
    PairWrapper<String, Object> wrapper = new PairWrapper<>();

    for (Schema.Field field : fields) {
        String key = field.name();
        Object value = record.get(key);
        // 分离存储是否关心顺序的key-value
        if (noorderKeys.contains(field.name())) {
            wrapper.addProperties(key, value);
        }
    }

    GenericRecord before = getFromRecord(MessageBodyKey.BEFORE, record);
    GenericRecord after = getFromRecord(MessageBodyKey.AFTER, record);

    Map<String, Object> beforeMap = convert2map(before);
    Map<String, Object> afterMap = convert2map(after);

    // 覆盖before
    mergeMap(beforeMap, afterMap);

    for (Map.Entry<String, Object> entry : beforeMap.entrySet()) {
        if(!entry.getKey().endsWith(MessageBodyKey.IS_MISSING_SUFFIX)) {
            wrapper.addPair(new Pair<>(entry.getKey(), CharSequence.class.isInstance(entry.getValue())?entry.getValue().toString():entry.getValue()));
        }
    }

    return wrapper;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:32,代码来源:BoltCommandHandlerHelper.java

示例11: internalValidate

import org.apache.avro.Schema; //导入方法依赖的package包/类
private void internalValidate(Schema schema) throws SchemaValidationException {
  if (schema.getType() == RECORD) {
    String name = schema.getFullName();
    if (recordTypeNames.contains(name)) {
      return;
    }
    recordTypeNames.add(name);
    for (Field field : schema.getFields()) {
      internalValidate(field.schema());
    }
  } else if (schema.getType() == MAP) {
    internalValidate(schema.getValueType());
  } else if (schema.getType() == ARRAY) {
    internalValidate(schema.getElementType());
  } else if (schema.getType() == UNION) {
    boolean containsBytes = false;
    boolean containsString = false;
    for (Schema unionSchema : schema.getTypes()) {
      if (unionSchema.getType() == Schema.Type.BYTES) {
        containsBytes = true;
      } else if (unionSchema.getType() == Schema.Type.STRING) {
        containsString = true;
      }
      if (containsBytes && containsString) {
        String message = "Schema contains a variant of union[bytes, string]: " + unionSchema.toString();
        throw new SchemaValidationException(message);
      }
      if (COMPOSITE_TYPES.contains(unionSchema)) {
        internalValidate(unionSchema);
      }
    }
  }
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:34,代码来源:SchemaValidator.java

示例12: getAllKey

import org.apache.avro.Schema; //导入方法依赖的package包/类
@Override
public String[] getAllKey() throws IOException{
  Schema schema = record.getSchema();
  List<Schema.Field> childFieldList = schema.getFields();
  String[] keys = new String[childFieldList.size()];
  for( int i = 0 ; i < childFieldList.size() ; i++ ){
    keys[i] = childFieldList.get(i).name();
  }

  return keys;
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:12,代码来源:AvroRecordParser.java

示例13: AvroRecordFormatter

import org.apache.avro.Schema; //导入方法依赖的package包/类
public AvroRecordFormatter( final Schema avroSchema ){
  this.avroSchema = avroSchema;

  childContainer = new ArrayList<KeyAndFormatter>();
  List<Schema.Field> childFields = avroSchema.getFields();
  for( Schema.Field field : childFields ){
    childContainer.add( new KeyAndFormatter( field.name() , field.schema() ) );
  }
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:10,代码来源:AvroRecordFormatter.java

示例14: AvroRecordSchema

import org.apache.avro.Schema; //导入方法依赖的package包/类
public AvroRecordSchema( final Schema avroSchema ) throws IOException{
  this.avroSchema = avroSchema;
  schema = new StructContainerField( avroSchema.getName() );

  for( Schema.Field field : avroSchema.getFields() ){
    schema.set( AvroSchemaFactory.getGeneralSchema( field.name() , field.schema() ) );
  }
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:9,代码来源:AvroRecordSchema.java

示例15: getFieldIgnoreCase

import org.apache.avro.Schema; //导入方法依赖的package包/类
private static Schema.Field getFieldIgnoreCase(Schema avroSchema,
    String fieldName) {
  for (Schema.Field field : avroSchema.getFields()) {
    if (field.name().equalsIgnoreCase(fieldName)) {
      return field;
    }
  }
  return null;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:10,代码来源:GenericRecordExportMapper.java


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