本文整理汇总了Java中org.apache.avro.generic.GenericArray类的典型用法代码示例。如果您正苦于以下问题:Java GenericArray类的具体用法?Java GenericArray怎么用?Java GenericArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericArray类属于org.apache.avro.generic包,在下文中一共展示了GenericArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listTables
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
public GenericArray<ATableDescriptor> listTables() throws AIOError {
try {
HTableDescriptor[] tables = admin.listTables();
Schema atdSchema = Schema.createArray(ATableDescriptor.SCHEMA$);
GenericData.Array<ATableDescriptor> result = null;
result = new GenericData.Array<ATableDescriptor>(tables.length, atdSchema);
for (HTableDescriptor table : tables) {
result.add(AvroUtil.htdToATD(table));
}
return result;
} catch (IOException e) {
AIOError ioe = new AIOError();
ioe.message = new Utf8(e.getMessage());
throw ioe;
}
}
示例2: get
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
public static IParser get( final Object obj ) throws IOException{
Schema.Type schemaType;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return new AvroNullParser();
}
switch( schemaType ){
case ARRAY:
return new AvroArrayParser( (GenericArray)obj );
case MAP:
return new AvroMapParser( (Map<Object,Object>)obj );
case RECORD:
return new AvroRecordParser( (GenericRecord)obj );
case UNION :
default:
return new AvroNullParser();
}
}
示例3: getArray
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
public static AvroValue getArray(AvroType type, Object value) {
if(type.getType() != Type.TypeName.ARRAY) {
throw new IllegalArgumentException("Can't create an array value with non-array schema: " + type.getType());
}
return new AvroValue(value, type) {
private final GenericArray<Object> array = (GenericArray<Object>)value;
@Override
public List<Object> arrayValue() {
return array;
}
@Override
public Value getElement(int index) {
return type.getElementType().build(array.get(index));
}
};
}
示例4: addGenericArray
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
public void addGenericArray(K key, String fieldName, GenericArray<?> array) {
if (isSuper( cassandraMapping.getFamily(fieldName) )) {
int i= 0;
for (Object itemValue: array) {
// TODO: hack, do not store empty arrays
if (itemValue instanceof GenericArray<?>) {
if (((List<?>)itemValue).size() == 0) {
continue;
}
} else if (itemValue instanceof Map<?,?>) {
if (((Map<?, ?>)itemValue).size() == 0) {
continue;
}
}
addSubColumn(key, fieldName, i++, itemValue);
}
}
else {
addColumn(key, fieldName, array);
}
}
示例5: writeBlock
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void writeBlock() {
if (logBlock != null) {
LOG.debug("Writing block: {} {}", logBlock.get("second"),
((GenericArray<String>) logBlock.get("logLines")).size());
try {
writer.append(logBlock);
} catch (IOException e) {
LOG.error("Error writing out record. Data lost.", e);
}
logBlock = null;
linesInBlock = 0;
}
}
示例6: unwrapElement
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
private static Element unwrapElement(GenericRecord record, Document doc) {
String name = "" + record.get("name");
Element el = doc.createElement(name);
@SuppressWarnings("unchecked")
GenericArray<GenericRecord> attrArray = (GenericArray<GenericRecord>) record.get("attributes");
for (GenericRecord attrRecord : attrArray)
el.setAttributeNode(unwrapAttr(attrRecord, doc));
@SuppressWarnings("unchecked")
GenericArray<Object> childArray = (GenericArray<Object>) record.get("children");
for (Object childObj : childArray) {
if (childObj instanceof GenericRecord)
el.appendChild(unwrapElement((GenericRecord) childObj, doc));
if (childObj instanceof Utf8)
el.appendChild(doc.createTextNode("" + childObj));
}
return el;
}
示例7: testInvalidArrayRecursiveType
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@Test()
public void testInvalidArrayRecursiveType()
throws Exception {
Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
byte[] bytes = mapper.writeValueAsBytes(ImmutableMap.of(
"collection", "test",
"api", api,
"properties", ImmutableMap.of("test0", "test",
"test1", ImmutableList.of("test", ImmutableMap.of("test", 2)),
"test2", false)));
Event event = mapper.readValue(bytes, Event.class);
GenericArray test1 = event.getAttribute("test1");
assertEquals(test1.get(0), "test");
assertEquals(test1.get(1), "{\"test\":2}");
}
示例8: unionResolver
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
public static Object unionResolver(Object o) {
if (o instanceof org.apache.avro.util.Utf8) {
return o.toString();
} else if (o instanceof IndexedRecord) {
return new AvroTupleWrapper<IndexedRecord>((IndexedRecord) o);
} else if (o instanceof GenericArray) {
return new AvroBagWrapper<GenericData.Record>(
(GenericArray<GenericData.Record>) o);
} else if (o instanceof Map) {
return new AvroMapWrapper((Map<CharSequence, Object>) o);
} else if (o instanceof GenericData.Fixed) {
return new DataByteArray(((GenericData.Fixed) o).bytes());
} else if (o instanceof ByteBuffer) {
return new DataByteArray(((ByteBuffer) o).array());
} else if (o instanceof GenericEnumSymbol) {
return o.toString();
} else {
return o;
}
}
示例9: updateRecord
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
private void updateRecord(CommonRecord record, GenericRecord delta) {
List<Field> deltaFields = delta.getSchema().getFields();
for (Field deltaField : deltaFields) {
String fieldName = deltaField.name();
Object rawDeltaField = delta.get(fieldName);
if (LOG.isDebugEnabled()) {
LOG.debug("Processing field \"{}\", current value: {}",
fieldName, record.getField(fieldName) != null ? record
.getField(fieldName).toString() : null);
}
if (AvroGenericUtils.isRecord(rawDeltaField)) {
processRecordField(record, (GenericRecord) rawDeltaField, fieldName);
} else if (AvroGenericUtils.isArray(rawDeltaField)) {
processArrayField(record, (GenericArray) rawDeltaField, fieldName);
} else if (AvroGenericUtils.isEnum(rawDeltaField)) {
processEnumField(record, (GenericEnumSymbol) rawDeltaField, fieldName);
} else if (AvroGenericUtils.isFixed(rawDeltaField)) {
processFixedField(record, (GenericFixed) rawDeltaField, fieldName);
} else {
record.setField(fieldName, commonFactory.createCommonValue(rawDeltaField));
}
}
}
示例10: processConfigurationData
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@Override
public synchronized void processConfigurationData(ByteBuffer buffer, boolean fullResync)
throws IOException {
if (buffer != null) {
if (schema == null) {
throw new ConfigurationRuntimeException(
"Can't process configuration update. Schema is null");
}
GenericAvroConverter<GenericArray<GenericRecord>> converter =
new GenericAvroConverter<>(schema);
GenericArray<GenericRecord> deltaArray = converter.decodeBinary(buffer.array());
for (GenericRecord delta : deltaArray) {
GenericRecord record = (GenericRecord) delta.get("delta");
int index = delta.getSchema().getField("delta").schema().getTypes().indexOf(
record.getSchema());
for (GenericDeltaReceiver subscriber : onDeltaReceived) {
subscriber.onDeltaReceived(index, record, fullResync);
}
}
for (ConfigurationProcessedObserver callback : onProcessed) {
callback.onConfigurationProcessed();
}
}
}
示例11: removeUuid
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
/**
* Recursively removes UUIDs from the record.
*
* @param baseRecord The record containing UUID fields.
*/
public static void removeUuid(GenericRecord baseRecord) {
Schema recordSchema = baseRecord.getSchema();
for (Schema.Field fieldSchema : recordSchema.getFields()) {
if (baseRecord.get(fieldSchema.name()) != null) {
Object field = baseRecord.get(fieldSchema.name());
if (field instanceof GenericFixed) {
baseRecord.put(fieldSchema.name(), clearUuid((GenericFixed) field, fieldSchema));
} else if (field instanceof GenericRecord) {
removeUuid((GenericRecord) field);
} else if (field instanceof GenericArray) {
GenericArray arrayField = (GenericArray) field;
for (Object obj : arrayField) {
if (obj instanceof GenericRecord) {
removeUuid((GenericRecord) obj);
}
}
}
}
}
}
示例12: getData
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@Override
public synchronized byte[] getData() throws IOException {
if (deltaQueue != null && !deltaQueue.isEmpty()) {
GenericArray deltaArray = new GenericData.Array(deltaQueue.size(),
schema);
while (!deltaQueue.isEmpty()) {
GenericRecord deltaT = new GenericData.Record(
schema.getElementType());
deltaT.put(DELTA, deltaQueue.poll());
deltaArray.add(deltaT);
}
GenericAvroConverter<GenericArray> converter = new GenericAvroConverter<>(schema);
serializedData = converter.encode(deltaArray);
if (LOG.isTraceEnabled()) {
LOG.trace("Delta array: {}", deltaArray.toString());
}
}
return serializedData != null ? Arrays.copyOf(serializedData,
serializedData.length) : null;
}
示例13: fillDeltaWithoutMerge
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
/**
* Fill delta without merge.
*
* @param delta the delta
* @param root the root
* @throws DeltaCalculatorException the delta calculator exception
*/
private void fillDeltaWithoutMerge(GenericRecord delta, GenericRecord root)
throws DeltaCalculatorException {
Schema rootSchema = root.getSchema();
for (Field field : rootSchema.getFields()) {
Object value = root.get(field.name());
if (value instanceof List) {
List<Object> values = (List<Object>) value;
Schema arraySchema = getArraySchema(delta, field.name());
GenericArray deltaArray = new GenericData.Array(values.size(), arraySchema);
for (Object item : values) {
if (item instanceof GenericContainer) {
GenericContainer record = (GenericContainer) item;
addComplexItemToArray(record, deltaArray);
} else {
deltaArray.add(item);
}
}
delta.put(field.name(), deltaArray);
} else if (value instanceof GenericContainer) {
processComplexField(delta, field.name(), (GenericContainer) value, null, null);
} else {
delta.put(field.name(), value);
}
}
}
示例14: cloneObject
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object cloneObject(Schema schema, Object toClone, Object cloned) {
if(toClone == null) {
return null;
}
switch(schema.getType()) {
case MAP :
Map<Utf8, Object> map = (Map<Utf8, Object>)newMap(cloned, 0);
for(Map.Entry<Utf8, Object> entry: ((Map<Utf8, Object>)toClone).entrySet()) {
map.put((Utf8)createString(entry.getKey().toString())
, cloneObject(schema.getValueType(), entry.getValue(), null));
}
return map;
case ARRAY :
GenericArray<Object> array = (GenericArray<Object>)
newArray(cloned, (int)((GenericArray<?>)toClone).size(), schema);
for(Object element: (GenericArray<Object>)toClone) {
array.add(cloneObject(schema.getElementType(), element, null));
}
return array;
case RECORD : return clone((Persistent)toClone, schema);
case STRING : return createString(toClone.toString());
default : return toClone; //shallow copy is enough
}
}
示例15: addGenericArray
import org.apache.avro.generic.GenericArray; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void addGenericArray(K key, String fieldName, GenericArray array) {
if (isSuper( cassandraMapping.getFamily(fieldName) )) {
int i= 0;
for (Object itemValue: array) {
// TODO: hack, do not store empty arrays
if (itemValue instanceof GenericArray<?>) {
if (((GenericArray)itemValue).size() == 0) {
continue;
}
} else if (itemValue instanceof StatefulHashMap<?,?>) {
if (((StatefulHashMap)itemValue).size() == 0) {
continue;
}
}
addSubColumn(key, fieldName, i++, itemValue);
}
}
else {
addColumn(key, fieldName, array);
}
}