Search in sources :

Example 1 with AvroVersionedGenericSerializer

use of voldemort.serialization.avro.versioned.AvroVersionedGenericSerializer in project voldemort by voldemort.

the class AvroStoreBuilderMapper method configure.

@Override
public void configure(JobConf conf) {
    super.setConf(conf);
    this.mapper.configure(conf);
    List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new StringReader(conf.get("stores.xml")));
    if (storeDefs.size() != 1)
        throw new IllegalStateException("Expected to find only a single store, but found multiple!");
    this.storeDef = storeDefs.get(0);
    keySerializerDefinition = getStoreDef().getKeySerializer();
    valueSerializerDefinition = getStoreDef().getValueSerializer();
    try {
        keyField = conf.get(VoldemortBuildAndPushJob.AVRO_KEY_FIELD);
        valField = conf.get(VoldemortBuildAndPushJob.AVRO_VALUE_FIELD);
        keySchema = conf.get(AVRO_KEY_SCHEMA);
        valSchema = conf.get(AVRO_VALUE_SCHEMA);
        if (keySerializerDefinition.getName().equals(DefaultSerializerFactory.AVRO_GENERIC_TYPE_NAME)) {
            keySerializer = new AvroGenericSerializer(keySchema);
            valueSerializer = new AvroGenericSerializer(valSchema);
        } else {
            if (keySerializerDefinition.hasVersion()) {
                Map<Integer, String> versions = new HashMap<Integer, String>();
                for (Map.Entry<Integer, String> entry : keySerializerDefinition.getAllSchemaInfoVersions().entrySet()) versions.put(entry.getKey(), entry.getValue());
                keySerializer = new AvroVersionedGenericSerializer(versions);
            } else
                keySerializer = new AvroVersionedGenericSerializer(keySerializerDefinition.getCurrentSchemaInfo());
            if (valueSerializerDefinition.hasVersion()) {
                Map<Integer, String> versions = new HashMap<Integer, String>();
                for (Map.Entry<Integer, String> entry : valueSerializerDefinition.getAllSchemaInfoVersions().entrySet()) versions.put(entry.getKey(), entry.getValue());
                valueSerializer = new AvroVersionedGenericSerializer(versions);
            } else
                valueSerializer = new AvroVersionedGenericSerializer(valueSerializerDefinition.getCurrentSchemaInfo());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AvroGenericSerializer(voldemort.serialization.avro.AvroGenericSerializer) AvroVersionedGenericSerializer(voldemort.serialization.avro.versioned.AvroVersionedGenericSerializer) HashMap(java.util.HashMap) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 VoldemortException (voldemort.VoldemortException)1 AvroGenericSerializer (voldemort.serialization.avro.AvroGenericSerializer)1 AvroVersionedGenericSerializer (voldemort.serialization.avro.versioned.AvroVersionedGenericSerializer)1 StoreDefinition (voldemort.store.StoreDefinition)1 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)1