本文整理汇总了Java中org.apache.avro.generic.GenericArray.get方法的典型用法代码示例。如果您正苦于以下问题:Java GenericArray.get方法的具体用法?Java GenericArray.get怎么用?Java GenericArray.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.generic.GenericArray
的用法示例。
在下文中一共展示了GenericArray.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collapseSameType
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
protected void collapseSameType(GenericRecord obj) {
for (Field f : obj.getSchema().getFields()) {
Object value = obj.get(f.name());
if(value == null)
{
continue;
}
if (value instanceof GenericRecord)
collapseSameType((GenericRecord)value);
if (value instanceof GenericArray) {
GenericArray array = (GenericArray)value;
Set<Object> valuesHash = new HashSet<Object>();
boolean unmodified = true;
for (int i = 0; i < array.size(); i++) {
Object o = array.get(i);
if (o instanceof GenericRecord)
collapseSameType((GenericRecord) o);
unmodified &= valuesHash.add(o);
}
if(!unmodified)
{
GenericArray<Object> newValues = new GenericData.Array<Object>(array.getSchema(), valuesHash);
obj.put(f.name(), newValues);
}
}
}
}
示例2: testArrayOfFixed
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfFixed() {
Schema fixedSchema = Schema.createFixed("someFixed", "", "", 2);
GenericArray avroArray = CommonToGeneric.createArray(createCommonArray(
fixedSchema, new DefaultCommonFixed(fixedSchema, new byte[]{1, 2})));
GenericFixed avroFixed = (GenericFixed) avroArray.get(0);
assertArrayEquals(new byte[]{1, 2}, avroFixed.bytes());
}
示例3: testArrayOfBoolean
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfBoolean() {
Schema booleanSchema = Schema.create(Type.BOOLEAN);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
booleanSchema, new Boolean(Boolean.TRUE)));
Boolean avroBoolean = (Boolean) avroArray.get(0);
assertTrue(avroBoolean);
}
示例4: testArrayOfInteger
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfInteger() {
Schema integerSchema = Schema.create(Type.INT);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
integerSchema, new Integer(5)));
Integer avroInt = (Integer) avroArray.get(0);
assertEquals(5, avroInt.intValue());
}
示例5: testArrayOfLong
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfLong() {
Schema longSchema = Schema.create(Type.LONG);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
longSchema, new Long(5)));
Long avroLong = (Long) avroArray.get(0);
assertEquals(5, avroLong.longValue());
}
示例6: testArrayOfDouble
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfDouble() {
Schema doubleSchema = Schema.create(Type.DOUBLE);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
doubleSchema, new Double(5.5)));
Double avroDouble = (Double) avroArray.get(0);
assertEquals(5.5, avroDouble.doubleValue(), 0.1);
}
示例7: testArrayOfFloat
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfFloat() {
Schema floatSchema = Schema.create(Type.FLOAT);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
floatSchema, new Float(5.5)));
Float avroFloat = (Float) avroArray.get(0);
assertEquals(5.5, avroFloat.floatValue(), 0.1);
}
示例8: testArrayOfString
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfString() {
Schema stringSchema = Schema.create(Type.STRING);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
stringSchema, new String("abc")));
String avroString = (String) avroArray.get(0);
assertEquals("abc", avroString);
}
示例9: testArrayOfBytes
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testArrayOfBytes() {
Schema bytesSchema = Schema.create(Type.BYTES);
GenericArray avroArray = CommonToGeneric
.createArray(createCommonArray(
bytesSchema, ByteBuffer.wrap(new byte[]{1, 2})));
ByteBuffer avroBytes = (ByteBuffer) avroArray.get(0);
assertArrayEquals(new byte[]{1, 2}, avroBytes.array());
}
示例10: testValidationOfArrayFields
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testValidationOfArrayFields() throws Exception {
// Read Configuration Schema
Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/arraySchema.json").toURI());
BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));
Schema.Parser schemaParser = new Schema.Parser();
Schema avroSchema = schemaParser.parse(configuraionSchema.getRawSchema());
GenericRecord recordNew1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew1.put("intField", 4);
GenericFixed uuidNew1 = AvroUtils.generateUuidObject();
recordNew1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordNew2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew2.put("intField", 5);
GenericFixed uuidNew2 = AvroUtils.generateUuidObject();
recordNew2.put(CommonConstants.UUID_FIELD, uuidNew2);
GenericRecord rootNew = new GenericData.Record(avroSchema);
GenericArray arrayNew = new GenericData.Array<>(2, rootNew.getSchema().getField("complexArrayField").schema());
arrayNew.add(recordNew1);
arrayNew.add(recordNew2);
rootNew.put("complexArrayField", arrayNew);
GenericRecord recordOld1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld1.put("intField", 6);
recordOld1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordOld2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld2.put("intField", 7);
GenericFixed uuidOld2 = AvroUtils.generateUuidObject();
recordOld2.put(CommonConstants.UUID_FIELD, uuidOld2);
GenericRecord rootOld = new GenericData.Record(avroSchema);
GenericArray arrayOld = new GenericData.Array<>(2, rootOld.getSchema().getField("complexArrayField").schema());
arrayOld.add(recordOld1);
arrayOld.add(recordOld2);
rootOld.put("complexArrayField", arrayOld);
rootOld.put(CommonConstants.UUID_FIELD, AvroUtils.generateUuidObject());
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(avroSchema);
String configurationBodyNew = converter.encodeToJson(rootNew);
String configurationBodyOld = converter.encodeToJson(rootOld);
DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(rootNew, rootOld);
GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());
GenericArray processedArray = (GenericArray) processedConfiguration.get("complexArrayField");
GenericRecord record1 = (GenericRecord) processedArray.get(0);
GenericRecord record2 = (GenericRecord) processedArray.get(1);
Assert.assertEquals(uuidNew1, record1.get(CommonConstants.UUID_FIELD));
Assert.assertNotEquals(uuidNew2, record2.get(CommonConstants.UUID_FIELD));
Assert.assertNotNull(processedConfiguration.get(CommonConstants.UUID_FIELD));
}
示例11: testValidationOfDifferentTypes
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testValidationOfDifferentTypes() throws Exception {
// Read Configuration Schema
Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/arraySchema.json").toURI());
BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));
Schema.Parser schemaParser = new Schema.Parser();
Schema avroSchema = schemaParser.parse(configuraionSchema.getRawSchema());
GenericRecord recordNew1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew1.put("intField", 4);
GenericFixed uuidNew1 = AvroUtils.generateUuidObject();
recordNew1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordNew2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew2.put("intField", 5);
GenericFixed uuidNew2 = AvroUtils.generateUuidObject();
recordNew2.put(CommonConstants.UUID_FIELD, uuidNew2);
GenericRecord rootNew = new GenericData.Record(avroSchema);
GenericArray arrayNew = new GenericData.Array<>(2, rootNew.getSchema().getField("complexArrayField").schema());
arrayNew.add(recordNew1);
arrayNew.add(recordNew2);
rootNew.put("complexArrayField", arrayNew);
rootNew.put(CommonConstants.UUID_FIELD, uuidNew2);
GenericRecord recordOld1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld1.put("intField", 6);
recordOld1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordOld2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld2.put("intField", 7);
GenericFixed uuidOld2 = AvroUtils.generateUuidObject();
recordOld2.put(CommonConstants.UUID_FIELD, uuidOld2);
GenericRecord rootOld = new GenericData.Record(avroSchema);
GenericArray arrayOld = new GenericData.Array<>(2, rootOld.getSchema().getField("complexArrayField").schema());
arrayOld.add(recordOld1);
arrayOld.add(recordOld2);
rootOld.put("complexArrayField", arrayOld);
rootOld.put(CommonConstants.UUID_FIELD, uuidNew2);
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(avroSchema);
String configurationBodyNew = converter.encodeToJson(rootNew);
String configurationBodyOld = converter.encodeToJson(rootOld);
DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(rootNew, rootOld);
GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());
GenericArray processedArray = (GenericArray) processedConfiguration.get("complexArrayField");
GenericRecord record1 = (GenericRecord) processedArray.get(0);
GenericRecord record2 = (GenericRecord) processedArray.get(1);
Assert.assertEquals(uuidNew1, record1.get(CommonConstants.UUID_FIELD));
Assert.assertNotEquals(uuidNew2, record2.get(CommonConstants.UUID_FIELD));
Assert.assertEquals(uuidNew2, processedConfiguration.get(CommonConstants.UUID_FIELD));
}
示例12: testValidationOfIdenticalUuids
import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Test
public void testValidationOfIdenticalUuids() throws Exception {
// Read Configuration Schema
Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/arraySchema.json").toURI());
BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));
Schema.Parser schemaParser = new Schema.Parser();
Schema avroSchema = schemaParser.parse(configuraionSchema.getRawSchema());
GenericRecord recordNew1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew1.put("intField", 4);
GenericFixed uuidNew1 = AvroUtils.generateUuidObject();
recordNew1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordNew2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordNew2.put("intField", 5);
recordNew2.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord rootNew = new GenericData.Record(avroSchema);
GenericArray arrayNew = new GenericData.Array<>(2, rootNew.getSchema().getField("complexArrayField").schema());
arrayNew.add(recordNew1);
arrayNew.add(recordNew2);
rootNew.put("complexArrayField", arrayNew);
GenericRecord recordOld1 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld1.put("intField", 6);
recordOld1.put(CommonConstants.UUID_FIELD, uuidNew1);
GenericRecord recordOld2 = new GenericData.Record(schemaParser.getTypes().get("org.kaaproject.recordT"));
recordOld2.put("intField", 7);
GenericFixed uuidOld2 = AvroUtils.generateUuidObject();
recordOld2.put(CommonConstants.UUID_FIELD, uuidOld2);
GenericRecord rootOld = new GenericData.Record(avroSchema);
GenericArray arrayOld = new GenericData.Array<>(2, rootOld.getSchema().getField("complexArrayField").schema());
arrayOld.add(recordOld1);
arrayOld.add(recordOld2);
rootOld.put("complexArrayField", arrayOld);
rootOld.put(CommonConstants.UUID_FIELD, AvroUtils.generateUuidObject());
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(avroSchema);
String configurationBodyNew = converter.encodeToJson(rootNew);
String configurationBodyOld = converter.encodeToJson(rootOld);
DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(rootNew, rootOld);
GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());
GenericArray processedArray = (GenericArray) processedConfiguration.get("complexArrayField");
GenericRecord record1 = (GenericRecord) processedArray.get(0);
GenericRecord record2 = (GenericRecord) processedArray.get(1);
Assert.assertEquals(uuidNew1, record1.get(CommonConstants.UUID_FIELD));
Assert.assertNotEquals(uuidNew1, record2.get(CommonConstants.UUID_FIELD));
Assert.assertNotNull(processedConfiguration.get(CommonConstants.UUID_FIELD));
}