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