本文整理汇总了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;
}
示例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"));
}
示例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;
}
示例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"));
}
示例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"));
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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()));
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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() ) );
}
}
示例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() ) );
}
}
示例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;
}