Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericData


    assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
  }

  @Test public void testUnionWithBytes() {
    Schema s = new Schema.Parser().parse ("[\"null\", \"bytes\"]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, ByteBuffer.wrap(new byte[]{1})));
  }
View Full Code Here


  }

  @Test public void testUnionWithCollection() {
    Schema s = Schema.parse
      ("[\"null\", {\"type\":\"array\",\"items\":\"float\"}]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, new ArrayList<Float>()));
  }
View Full Code Here

  }

  @Test public void testUnionWithMap() {
    Schema s = Schema.parse
      ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
  }
View Full Code Here

    assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
  }

  @Test public void testUnionWithBytes() {
    Schema s = Schema.parse ("[\"null\", \"bytes\"]");
    GenericData data = ReflectData.get();
    assertEquals(1, data.resolveUnion(s, ByteBuffer.wrap(new byte[]{1})));
  }
View Full Code Here

    Configuration conf = getConf();
    boolean isKey = AvroKey.class.isAssignableFrom(c);
    Schema schema = isKey
      ? Pair.getKeySchema(AvroJob.getMapOutputSchema(conf))
      : Pair.getValueSchema(AvroJob.getMapOutputSchema(conf));
    GenericData dataModel = AvroJob.createMapOutputDataModel(conf);
    DatumReader<T> datumReader = dataModel.createDatumReader(schema);
    return new AvroWrapperDeserializer(datumReader, isKey);
  }
View Full Code Here

    SeekableInput seekableFileInput
        = createSeekableInput(context.getConfiguration(), fileSplit.getPath());

    // Wrap the seekable input stream in an Avro DataFileReader.
    Configuration conf = context.getConfiguration();
    GenericData dataModel = AvroSerialization.createDataModel(conf);
    DatumReader<T> datumReader = dataModel.createDatumReader(mReaderSchema);
    mAvroFileReader = createAvroFileReader(seekableFileInput, datumReader);

    // Initialize the start and end offsets into the file based on the boundaries of the
    // input split we're responsible for.  We will read the first block that begins
    // after the input split start boundary.  We will read up to but not including the
View Full Code Here

    Schema schema = isFinalOutput
      ? AvroJob.getOutputSchema(conf)
      : (AvroKey.class.isAssignableFrom(c)
         ? Pair.getKeySchema(AvroJob.getMapOutputSchema(conf))
         : Pair.getValueSchema(AvroJob.getMapOutputSchema(conf)));
    GenericData dataModel = AvroJob.createDataModel(conf);
    return new AvroWrapperSerializer(dataModel.createDatumWriter(schema));
  }
View Full Code Here

    AvroDatumConverter<K, ?> keyConverter = converterFactory.create(
        (Class<K>) context.getOutputKeyClass());
    AvroDatumConverter<V, ?> valueConverter = converterFactory.create(
        (Class<V>) context.getOutputValueClass());

    GenericData dataModel = AvroSerialization.createDataModel(conf);

    return new AvroKeyValueRecordWriter<K, V>(keyConverter, valueConverter,
        dataModel, getCompressionCodec(context), getAvroFileOutputStream(context));
  }
View Full Code Here

    if (null == writerSchema) {
      throw new IOException(
          "AvroKeyOutputFormat requires an output schema. Use AvroJob.setOutputKeySchema().");
    }

    GenericData dataModel = AvroSerialization.createDataModel(conf);

    return mRecordWriterFactory.create
      (writerSchema, dataModel, getCompressionCodec(context),
       getAvroFileOutputStream(context));
  }
View Full Code Here

    return (Class<? extends GenericData>) conf.getClass(
        CONF_DATA_MODEL, ReflectData.class, GenericData.class);
  }

  private static GenericData newDataModelInstance(Class<? extends GenericData> modelClass, Configuration conf) {
    GenericData dataModel;
    try {
      Constructor<? extends GenericData> ctor = modelClass.getDeclaredConstructor(ClassLoader.class);
      ctor.setAccessible(true);
      dataModel = ctor.newInstance(conf.getClassLoader());
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.GenericData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.