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


Java GenericFixed类代码示例

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


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

示例1: processRecordField

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
private void processRecordField(
        CommonRecord record, GenericRecord deltaRecord, String fieldName) {
  CommonRecord nextRecord = null;
  CommonValue nextValue = record.getField(fieldName);
  if (nextValue != null
      && nextValue.isRecord()
      && nextValue.getRecord().getSchema().getFullName()
      .equals(deltaRecord.getSchema().getFullName())) {
    nextRecord = nextValue.getRecord();
    GenericFixed uuidFixed = (GenericFixed) deltaRecord.get(UUID);
    if (uuidFixed != null) {
      UUID uuid = AvroGenericUtils.createUuidFromFixed(uuidFixed);
      // Checking if the uuid was changed
      if (!uuid.equals(nextRecord.getUuid())) {
        records.remove(nextRecord.getUuid());
        records.put(uuid, nextRecord);
        nextRecord.setUuid(uuid);
      }
    }
  } else {
    nextRecord = createCommonRecord(deltaRecord);
    record.setField(fieldName, commonFactory.createCommonValue(nextRecord));
  }
  updateRecord(nextRecord, deltaRecord);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:26,代码来源:DefaultConfigurationManager.java

示例2: updateRecord

import org.apache.avro.generic.GenericFixed; //导入依赖的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));
    }
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:24,代码来源:DefaultConfigurationManager.java

示例3: onDeltaReceived

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Override
public synchronized void onDeltaReceived(int index, GenericRecord data, boolean fullResync) {
  GenericFixed uuidFixed = (GenericFixed) data.get(UUID);
  UUID uuid = AvroGenericUtils.createUuidFromFixed(uuidFixed);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Processing delta with uuid {}", uuidFixed.toString());
  }
  CommonRecord currentRecord = null;
  if (!fullResync && records.containsKey(uuid)) {
    currentRecord = records.get(uuid);
  } else {
    records.clear();
    currentRecord = createCommonRecord(data);
    rootRecord = currentRecord;
  }
  updateRecord(currentRecord, data);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:18,代码来源:DefaultConfigurationManager.java

示例4: removeUuid

import org.apache.avro.generic.GenericFixed; //导入依赖的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);
          }
        }
      }
    }
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:26,代码来源:AvroDataCanonizationUtils.java

示例5: testGeneration

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Test
public void testGeneration() throws Exception {
  // Read Configuration Schema
  Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/simpleSchema.json").toURI());
  BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));

  Path configurationPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/simpleConfiguration.json").toURI());
  String configuraion = new String(Files.readAllBytes(configurationPath));

  GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(configuraionSchema.getRawSchema());

  // generated default configuration
  DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
  KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(new BaseData(configuraionSchema, configuraion), null);

  GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());

  Object uuid = processedConfiguration.get(CommonConstants.UUID_FIELD);
  Assert.assertNotNull(uuid);
  Assert.assertTrue(uuid instanceof GenericFixed);
  Assert.assertEquals(CommonConstants.KAA_NAMESPACE + "." + CommonConstants.UUID_TYPE, ((GenericFixed) uuid).getSchema().getFullName());
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:23,代码来源:DefaultUuidValidatorTest.java

示例6: testValidationWithoutOldConfiguration

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Test
public void testValidationWithoutOldConfiguration() throws Exception {
  // Read Configuration Schema
  Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/simpleSchema.json").toURI());
  BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));
  Schema avroSchema = new Schema.Parser().parse(configuraionSchema.getRawSchema());
  GenericRecord record = new GenericData.Record(avroSchema);
  record.put("intField", 5);
  GenericFixed uuid = AvroUtils.generateUuidObject();
  record.put(CommonConstants.UUID_FIELD, uuid);

  GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(avroSchema);
  String configurationBody = converter.encodeToJson(record);

  DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
  KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(new BaseData(configuraionSchema, configurationBody), null);

  GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());
  Assert.assertNotEquals(processedConfiguration.get(CommonConstants.UUID_FIELD), uuid);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:21,代码来源:DefaultUuidValidatorTest.java

示例7: testValidationWithOldConfiguration

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Test
public void testValidationWithOldConfiguration() throws Exception {
  // Read Configuration Schema
  Path schemaPath = Paths.get(Thread.currentThread().getContextClassLoader().getResource("generation/simpleSchema.json").toURI());
  BaseSchema configuraionSchema = new BaseSchema(new String(Files.readAllBytes(schemaPath)));
  Schema avroSchema = new Schema.Parser().parse(configuraionSchema.getRawSchema());
  GenericRecord recordNew = new GenericData.Record(avroSchema);
  recordNew.put("intField", 4);
  GenericFixed uuidNew = AvroUtils.generateUuidObject();
  recordNew.put(CommonConstants.UUID_FIELD, uuidNew);

  GenericRecord recordOld = new GenericData.Record(avroSchema);
  recordOld.put("intField", 5);
  GenericFixed uuidOld = AvroUtils.generateUuidObject();
  recordOld.put(CommonConstants.UUID_FIELD, uuidOld);

  GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(avroSchema);
  String configurationBodyNew = converter.encodeToJson(recordNew);
  String configurationBodyOld = converter.encodeToJson(recordOld);

  DefaultUuidValidator uuidGenerator = new DefaultUuidValidator(configuraionSchema, new BaseDataFactory());
  KaaData processedConfigurationBody = uuidGenerator.validateUuidFields(recordNew, recordOld);

  GenericRecord processedConfiguration = converter.decodeJson(processedConfigurationBody.getRawData());
  Assert.assertEquals(processedConfiguration.get(CommonConstants.UUID_FIELD), uuidOld);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:27,代码来源:DefaultUuidValidatorTest.java

示例8: getComplexFieldDelta

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
public static AvroBinaryDelta getComplexFieldDelta(Schema schema) {
  GenericRecord delta = new GenericData.Record(getDeltaSchemaByFullName(schema, "org.kaa.config.testT"));
  GenericEnumSymbol unchanged = new GenericData.EnumSymbol(getSchemaByFullName(delta.getSchema().getField("testField1").schema().getTypes(),
      "org.kaaproject.configuration.unchangedT"), "unchanged");
  GenericRecord testField2 = new GenericData.Record(getSchemaByFullName(delta.getSchema().getField("testField2").schema().getTypes(),
      "org.kaa.config.testRecordT"));
  testField2.put("testField3", 456);
  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("testField1", unchanged);
  delta.put("testField2", testField2);
  delta.put("__uuid", uuid);

  AvroBinaryDelta deltaExpected = new AvroBinaryDelta(schema);
  deltaExpected.addDelta(delta);
  return deltaExpected;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:18,代码来源:DefaultDeltaCalculatorTest.java

示例9: schemaOfTypeFixed

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Test
public void schemaOfTypeFixed() throws JsonProcessingException, IOException {
  Schema schema = SchemaBuilder.builder().fixed("com.foo.IPv4").size(4);
  JsonNode datum = mapper.readTree("\"zzzz\"");
  Object actualObj = JasvornoConverter.convertToAvro(datum, schema);
  byte[] bytes = ("zzzz").getBytes();
  GenericFixed expected = new Fixed(schema, bytes);
  assertTrue(actualObj instanceof GenericFixed);
  assertThat(actualObj, is(expected));
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:11,代码来源:JasvornoConverterTest.java

示例10: apply

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
@Override
public GenericFixed apply(GeneratorContext input) {
    if (schema == null) {
        schema = new Schema.Parser().parse(jsonSchema);
    }
    byte[] buffer = new byte[size];
    input.getRandom().nextBytes(buffer);
    return new GenericData.Fixed(schema, buffer);
}
 
开发者ID:Talend,项目名称:components,代码行数:10,代码来源:GeneratorFunctions.java

示例11: readFixed

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
/**
 * Called to read a fixed value. Overridden to read a pig byte array.
 */
@Override
protected Object readFixed(Object old, Schema expected, Decoder in) throws IOException {
    GenericFixed fixed = (GenericFixed) super.readFixed(old, expected, in);
    DataByteArray byteArray = new DataByteArray(fixed.bytes());
    return byteArray;
 }
 
开发者ID:linkedin,项目名称:Cubert,代码行数:10,代码来源:PigAvroDatumReader.java

示例12: createCommonRecord

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
private CommonRecord createCommonRecord(GenericRecord avroRecord) {
  GenericFixed uuidFixed = (GenericFixed) avroRecord.get(UUID);
  if (uuidFixed != null) {
    UUID uuid = AvroGenericUtils.createUuidFromFixed(uuidFixed);
    CommonRecord newRecord = commonFactory.createCommonRecord(uuid, avroRecord.getSchema());
    records.put(uuid, newRecord);
    return newRecord;
  } else {
    return commonFactory.createCommonRecord(avroRecord.getSchema());
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:12,代码来源:DefaultConfigurationManager.java

示例13: createUuidFromFixed

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
/**
 * Creates UUID from the given GenericFixed object.
 *
 * @param fixed the fixed
 * @return uuid object.
 */
public static UUID createUuidFromFixed(GenericFixed fixed) {
  ByteBuffer bb = ByteBuffer.wrap(fixed.bytes());
  long first = bb.getLong();
  long second = bb.getLong();

  return new UUID(first, second);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:14,代码来源:AvroGenericUtils.java

示例14: isUuid

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
/**
 * Checks if the given value is UUID (value's schema is "org.kaaproject.configuration.uuidT").
 *
 * @param field object which going to be verified.
 * @return true if the value is UUID, false otherwise.
 */
public static boolean isUuid(Object field) {
  if (!isFixed(field)) {
    return false;
  }
  GenericFixed checkFixed = (GenericFixed) field;
  return checkFixed.getSchema().getFullName().equals(UUIDT);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:14,代码来源:AvroGenericUtils.java

示例15: fillComplexFullResyncDelta

import org.apache.avro.generic.GenericFixed; //导入依赖的package包/类
public static void fillComplexFullResyncDelta(GenericRecord delta) {
  GenericRecord testField2 = new GenericData.Record(getSchemaByFullName(
      delta.getSchema().getField("testField2").schema().getTypes(),
      "org.kaa.config.testRecordT"));
  testField2.put("testField3", 456);
  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("testField1", "abc");
  delta.put("testField2", testField2);
  delta.put("__uuid", uuid);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:13,代码来源:DefaultConfigurationManagerTest.java


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