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


Java GenericArray.add方法代码示例

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


在下文中一共展示了GenericArray.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:21,代码来源:AvroBinaryDelta.java

示例2: 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);
    }
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:33,代码来源:DefaultDeltaCalculationAlgorithm.java

示例3: 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
  }
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:27,代码来源:PersistentDatumReader.java

示例4: jsonColumn

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Override
public GenericArray<Object> jsonColumn(Value value) {
    if (!value.isArrayValue())
        throw new RuntimeException("Support only array type json record");

    List<Value> list = value.asArrayValue().list();

    GenericArray<Object> array = new GenericData.Array<>(list.size(), avroSchema);
    for (Value val : list) {
        switch (val.getValueType()) {
            case STRING:
                array.add(elementConverter.stringColumn(val.asStringValue().toString()));
                break;
            case INTEGER:
                array.add(elementConverter.longColumn(val.asIntegerValue().toLong()));
                break;
            case FLOAT:
                array.add(elementConverter.doubleColumn(val.asFloatValue().toDouble()));
                break;
            case BOOLEAN:
                array.add(elementConverter.booleanColumn(val.asBooleanValue().getBoolean()));
                break;
            case ARRAY:
                array.add(elementConverter.jsonColumn(val.asArrayValue()));
                break;
            case MAP:
                array.add(elementConverter.jsonColumn(val.asMapValue()));
                break;
            default:
                throw new RuntimeException("Irregular Messagepack type");
        }
    }
    return array;
}
 
开发者ID:joker1007,项目名称:embulk-formatter-avro,代码行数:35,代码来源:AvroArrayConverter.java

示例5: testFamilyAdminAndMetadata

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
/**
 * Tests for creating, modifying, and deleting column families.
 *
 * @throws Exception
 */
@Test
public void testFamilyAdminAndMetadata() throws Exception {
  AvroServer.HBaseImpl impl =
    new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration());

  ATableDescriptor tableA = new ATableDescriptor();
  tableA.name = tableAname;
  AFamilyDescriptor familyA = new AFamilyDescriptor();
  familyA.name = familyAname;
  Schema familyArraySchema = Schema.createArray(AFamilyDescriptor.SCHEMA$);
  GenericArray<AFamilyDescriptor> families = new GenericData.Array<AFamilyDescriptor>(1, familyArraySchema);
  families.add(familyA);
  tableA.families = families;
  impl.createTable(tableA);
  assertEquals(impl.describeTable(tableAname).families.size(), 1);

  impl.disableTable(tableAname);
  assertFalse(impl.isTableEnabled(tableAname));

  familyA.maxVersions = 123456;
  impl.modifyFamily(tableAname, familyAname, familyA);
  assertEquals((int) impl.describeFamily(tableAname, familyAname).maxVersions, 123456);

  impl.deleteFamily(tableAname, familyAname);
  assertEquals(impl.describeTable(tableAname).families.size(), 0);

  impl.deleteTable(tableAname);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:34,代码来源:TestAvroServer.java

示例6: generatePersonRecord

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
private GenericRecord generatePersonRecord(Schema peopleSchema, String name, String email,String title, String homepage, String depiction,  String twitter)
{
	GenericRecord record = new GenericData.Record(peopleSchema);
	record.put("name", name);
	record.put("email", email);
	record.put("title", title);
	record.put("homepage", homepage);
	record.put("depiction", depiction);
	record.put("twitter", twitter);
	Schema userIdArraySchema = peopleSchema.getField("userids").schema();
	Schema userIdSchema = userIdArraySchema.getElementType();
	GenericArray<GenericRecord> useridrecords = new GenericData.Array<GenericRecord>(userIdArraySchema, new LinkedList<GenericRecord>());
	
	Random r = new Random();
	for(int j = 0; j < 2; j++)
	{
		StringBuilder idBuilder = new StringBuilder();
		for(int i = 0; i < 8; i++)
		{
			idBuilder.append((char)(r.nextInt(26) + 'a'));
		}
		GenericRecord userId = new GenericData.Record(userIdSchema);
		userId.put("type", idNames[r.nextInt(idNames.length)]);
		userId.put("id", idBuilder.toString());
		useridrecords.add(userId);
	}
	record.put("userids", useridrecords);
	return record;
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:30,代码来源:TestAvroRDFGenerator.java

示例7: writeLine

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
public void writeLine(long timestamp, String message) throws IOException {
  long ms = timestamp % 1000l;
  long second = timestamp / 1000l;
  if (logBlock != null && second != (Long) logBlock.get("second")) {
    LOG.debug("Flushing due to new second: old:{}, new:{}",
        (Long) logBlock.get("second"), second);
    writeBlock();
  }

  if (logBlock == null) {
    logBlock = new GenericData.Record(logBlockSchema);
    logBlock.put("second", second);
    logBlock.put("createTime", System.currentTimeMillis());
    logBlock.put("blockNumber", ++blockNumber);
    logBlock.put("logLines", new GenericData.Array<Record>(
        getMaxLinesPerRecord() / 8, messageWithMillisArraySchema));
  }

  @SuppressWarnings("unchecked")
  GenericArray<Record> logLines = (GenericArray<Record>) logBlock
      .get("logLines");
  Record record = new GenericData.Record(messageWithMillisSchema);
  record.put("ms", ms);
  record.put("eventId", 0);
  record.put("message", message);
  logLines.add(record);

  linesInBlock++;

  if (linesInBlock >= getMaxLinesPerRecord()) {
    LOG.debug("Hit max lines, flushing record.");
    writeBlock();
  }

}
 
开发者ID:blackberry,项目名称:BB-BigData-Log-Tools,代码行数:36,代码来源:BoomWriter.java

示例8: writeLine

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
public void writeLine(long timestamp, String message, int eventId,
    long createTime, long blockNumber) throws IOException {
  long ms = timestamp % 1000l;
  long second = timestamp / 1000l;

  if (logBlock != null) {
    if (second != (Long) logBlock.get("second")) {
      LOG.debug("Flushing due to change in second. old:{} new:{}",
          logBlock.get("second"), second);
      writeBlock();
    } else if (createTime != (Long) logBlock.get("createTime")) {
      LOG.debug("Flushing due to change in createTime. old:{} new:{}",
          logBlock.get("createTime"), createTime);
      writeBlock();
    } else if (blockNumber != (Long) logBlock.get("blockNumber")) {
      LOG.debug("Flushing due to change in blockNumber. old:{} new:{}",
          logBlock.get("blockNumber"), blockNumber);
      writeBlock();
    }
  }

  if (logBlock == null) {
    logBlock = new GenericData.Record(logBlockSchema);
    logBlock.put("second", second);
    logBlock.put("createTime", createTime);
    logBlock.put("blockNumber", blockNumber);
    logBlock.put("logLines", new GenericData.Array<Record>(
        getMaxLinesPerRecord() / 8, messageWithMillisArraySchema));
  }

  @SuppressWarnings("unchecked")
  GenericArray<Record> logLines = (GenericArray<Record>) logBlock
      .get("logLines");
  Record record = new GenericData.Record(messageWithMillisSchema);
  record.put("ms", ms);
  record.put("eventId", eventId);
  record.put("message", message);
  logLines.add(record);
}
 
开发者ID:blackberry,项目名称:BB-BigData-Log-Tools,代码行数:40,代码来源:ReBoomWriter.java

示例9: createArray

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
/**
 * Creates new GenericArray from the given CommonArray object.
 *
 * @param commonArray CommonArray object.
 * @return new GenericArray object.
 */
public static GenericArray createArray(CommonArray commonArray) {
  final Schema arraySchema = commonArray.getSchema();
  List<CommonValue> array = commonArray.getList();
  GenericArray avroArray = new GenericData.Array(array.size(), arraySchema);
  for (CommonValue value : array) {
    if (value.isRecord()) {
      avroArray.add(createRecord(value.getRecord()));
    } else if (value.isFixed()) {
      avroArray.add(createFixed(value.getFixed()));
    } else if (value.isBoolean()) {
      avroArray.add(value.getBoolean());
    } else if (value.isInteger()) {
      avroArray.add(value.getInteger());
    } else if (value.isLong()) {
      avroArray.add(value.getLong());
    } else if (value.isDouble()) {
      avroArray.add(value.getDouble());
    } else if (value.isFloat()) {
      avroArray.add(value.getFloat());
    } else if (value.isString()) {
      avroArray.add(value.getString());
    } else if (value.isBytes()) {
      avroArray.add(value.getBytes());
    }
  }
  return avroArray;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:34,代码来源:CommonToGeneric.java

示例10: getSerializedDelta

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
private static byte[] getSerializedDelta(Schema schema, GenericRecord delta) throws IOException {
  DefaultConfigurationManagerTest.fillComplexFullResyncDelta(delta);

  GenericRecord deltaHandler = new GenericData.Record(schema.getElementType());
  deltaHandler.put("delta", delta);
  GenericArray<GenericRecord> array = new GenericData.Array<GenericRecord>(1, schema);
  array.add(deltaHandler);

  GenericAvroConverter<GenericArray<GenericRecord>> converter = new GenericAvroConverter<GenericArray<GenericRecord>>(schema);
  return converter.encode(array);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:12,代码来源:DefaultConfigurationProcessorTest.java

示例11: fillArrayFullResyncDelta

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
public static void fillArrayFullResyncDelta(GenericRecord delta) {
  byte[] rawUuid = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
  GenericFixed uuid = new GenericData.Fixed(delta.getSchema()
      .getField("__uuid").schema(), rawUuid);
  delta.put("__uuid", uuid);

  GenericArray testField1 = new GenericData.Array(3, getArraySchema(delta, "testField1"));
  delta.put("testField1", testField1);

  GenericRecord itemRecord1 = new GenericData.Record(getSchemaByFullName(
      testField1.getSchema().getElementType().getTypes(),
      "org.kaa.config.testRecordItemT"));
  itemRecord1.put("testField2", 1);
  byte[] rawItemUuid1 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
  GenericFixed itemUuid1 = new GenericData.Fixed(itemRecord1
      .getSchema().getField("__uuid").schema(), rawItemUuid1);
  itemRecord1.put("__uuid", itemUuid1);

  GenericRecord itemRecord2 = new GenericData.Record(getSchemaByFullName(
      testField1.getSchema().getElementType().getTypes(),
      "org.kaa.config.testRecordItemT"));
  itemRecord2.put("testField2", 2);
  byte[] rawItemUuid2 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2};
  GenericFixed itemUuid2 = new GenericData.Fixed(itemRecord2
      .getSchema().getField("__uuid").schema(), rawItemUuid2);
  itemRecord2.put("__uuid", itemUuid2);

  GenericRecord itemRecord3 = new GenericData.Record(getSchemaByFullName(
      testField1.getSchema().getElementType().getTypes(),
      "org.kaa.config.testRecordItemT"));
  itemRecord3.put("testField2", 3);
  byte[] rawItemUuid3 = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3};
  GenericFixed itemUuid3 = new GenericData.Fixed(itemRecord3
      .getSchema().getField("__uuid").schema(), rawItemUuid3);
  itemRecord3.put("__uuid", itemUuid3);

  testField1.add(itemRecord1);
  testField1.add(itemRecord2);
  testField1.add(itemRecord3);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:41,代码来源:DefaultConfigurationManagerTest.java

示例12: fillArrayItemRemoveDelta

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
public static void fillArrayItemRemoveDelta(GenericRecord delta) {
  GenericArray testField1 = new GenericData.Array(1, getArraySchema(delta, "testField1"));

  byte[] rawUuidToRemove = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
  GenericFixed uuidToRemove = new GenericData.Fixed(getSchemaByFullName(
      testField1.getSchema().getElementType().getTypes(),
      "org.kaaproject.configuration.uuidT"), rawUuidToRemove);
  testField1.add(uuidToRemove);
  delta.put("testField1", testField1);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:11,代码来源:DefaultConfigurationManagerTest.java

示例13: addComplexItemToArray

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
/**
 * Adds the complex item to array.
 *
 * @param container the record
 * @param array     the array
 * @throws DeltaCalculatorException the delta calculator exception
 */
private void addComplexItemToArray(GenericContainer container, GenericArray array)
        throws DeltaCalculatorException {
  Schema itemSchema = getSchemaByFullName(array.getSchema(), getFullName(container));
  if (itemSchema.getType() == Type.RECORD) {
    GenericRecord subDelta = new GenericData.Record(itemSchema);
    fillDeltaWithoutMerge(subDelta, (GenericRecord) container);
    array.add(subDelta);
  } else {
    array.add(container);
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:19,代码来源:DefaultDeltaCalculationAlgorithm.java

示例14: fromByteBuffer

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
@Override
  public GenericArray<T> fromByteBuffer(ByteBuffer byteBuffer) {
    if (byteBuffer == null) {
      return null;
    }
    GenericArray<T> array = new ListGenericArray<T>(elementSchema);
int i = 0;
    while (true) {
      T element = null;
      try {
        if (size > 0) {
          element = elementSerializer.fromByteBuffer(byteBuffer);
        }
        else {
          int n = IntegerSerializer.get().fromByteBuffer(byteBuffer);
          byte[] bytes = new byte[n];
          byteBuffer.get(bytes, 0, n);
          element = elementSerializer.fromByteBuffer( BytesArraySerializer.get().toByteBuffer(bytes) );
        }
      } catch (BufferUnderflowException e) {
        break;
      }
      if (element == null) {
        break;
      }
      array.add(element);
    }
    return array;
  }
 
开发者ID:maestros,项目名称:gora-oraclenosql,代码行数:30,代码来源:GenericArraySerializer.java

示例15: convertAttributeToAvro

import org.apache.avro.generic.GenericArray; //导入方法依赖的package包/类
private static Object convertAttributeToAvro(String attributeName, Object tupleAttribute, Type tupleAttributeType,
		Schema avroSchema) {
	Object returnObject = null;
	MetaType metaType = tupleAttributeType.getMetaType();
	switch (metaType) {
	case BOOLEAN:
		returnObject = (Boolean) tupleAttribute;
		break;
	case FLOAT32:
		returnObject = (Float) tupleAttribute;
		break;
	case FLOAT64:
		returnObject = (Double) tupleAttribute;
		break;
	case INT32:
		returnObject = (Integer) tupleAttribute;
		break;
	case INT64:
		returnObject = (Long) tupleAttribute;
		break;
	case RSTRING:
		returnObject = ((RString) tupleAttribute).getString();
		break;
	case USTRING:
		returnObject = tupleAttribute.toString();
		break;
	case TUPLE:
		Tuple subTuple = (Tuple) tupleAttribute;
		StreamSchema subStreamSchema = subTuple.getStreamSchema();
		GenericRecord subDatum = convertTupleToAvro(subTuple, subStreamSchema, avroSchema);
		// Return the Avro record
		returnObject = subDatum;
		break;
	case LIST:
		@SuppressWarnings("unchecked")
		List<Object> subList = (List<Object>) tupleAttribute;
		// Obtain the type of the elements contained in the Streams list
		Type tupleElementType = ((CollectionType) tupleAttributeType).getElementType();
		// Obtain the type of the elements contained in the Avro array
		Schema avroArrayElementType = avroSchema.getElementType();
		// Now loop through all list elements and populate the associated
		// Avro array elements
		GenericArray<Object> subArray = new GenericData.Array<Object>(subList.size(), avroSchema);
		for (Object arrayElement : subList) {
			Object avroElement = convertAttributeToAvro(attributeName, arrayElement, tupleElementType,
					avroArrayElementType);
			subArray.add(avroElement);
		}
		// Return the Avro array
		returnObject = subArray;
		break;
	default:
		LOGGER.log(TraceLevel.WARN,
				"Ignoring attribute " + attributeName + " because of unsupported type " + metaType);
	}
	return returnObject;
}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:58,代码来源:TupleToAvroConverter.java


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