Java Code Examples for org.apache.avro.io.DecoderFactory#get()

The following examples show how to use org.apache.avro.io.DecoderFactory#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcComponentTestIT.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDataBinary() throws java.io.IOException {
    // given
    UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
    propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
    propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));

    String dataSetDefinitionName = "JDBCDataset";

    // when
    Response schemaResponse = given().body(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
                                     .accept(APPLICATION_JSON_UTF8_VALUE) //
                                     .post(getVersionPrefix() + "/runtimes/schema");
    schemaResponse.then().statusCode(200).log().ifError();

    Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());

    Response response = given().body(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(RuntimesController.AVRO_BINARY_MIME_TYPE_OFFICIAL_INVALID).post(getVersionPrefix() + "/runtimes/data"); //
    response.then().statusCode(200).log().ifError();

    // then
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    DecoderFactory decoderFactory = DecoderFactory.get();
    Decoder decoder = decoderFactory.binaryDecoder(response.asInputStream(), null);
    assertRecordsEqualsToTestValues(reader, decoder);
}
 
Example 2
Source File: JdbcComponentTestIT.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetData() throws java.io.IOException {
    // given
    UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
    propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
    propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));

    String dataSetDefinitionName = "JDBCDataset";

    Response schemaResponse = given().body(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(APPLICATION_JSON_UTF8_VALUE).post(getVersionPrefix() + "/runtimes/schema");
    schemaResponse.then().statusCode(200).log().ifError();

    Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());

    // when
    Response response = given().body(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(RuntimesController.AVRO_JSON_MIME_TYPE_OFFICIAL_INVALID)
            .post(getVersionPrefix() + "/runtimes/data");
    response.then().statusCode(200).log().ifError();

    // then
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    DecoderFactory decoderFactory = DecoderFactory.get();
    Decoder decoder = decoderFactory.jsonDecoder(schema, response.asInputStream());

    assertRecordsEqualsToTestValues(reader, decoder);
}
 
Example 3
Source File: EnvelopeSchemaConverter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * To remove certain fields from the Avro schema or records of a topic/table, set property
 * {topic/table name}.remove.fields={comma-separated, fully qualified field names} in workUnit.
 */
@Override
public EnvelopeSchemaConverter init(WorkUnitState workUnit) {
  if (workUnit.contains(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY)) {
    String removeFieldsPropName = workUnit.getProp(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY) + AvroProjectionConverter.REMOVE_FIELDS;
    if (workUnit.contains(removeFieldsPropName)) {
      this.fieldRemover = Optional.of(new AvroSchemaFieldRemover(workUnit.getProp(removeFieldsPropName)));
    } else {
      this.fieldRemover = Optional.absent();
    }
  }
  String registryFactoryField = workUnit.contains(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) ?
      workUnit.getProp(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) : DEFAULT_KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS;
  try {
    KafkaSchemaRegistryFactory registryFactory = ((Class<? extends KafkaSchemaRegistryFactory>) Class.forName(registryFactoryField)).newInstance();
    this.registry = registryFactory.create(workUnit.getProperties());
  } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
    return null;
  }
  this.decoderFactory = DecoderFactory.get();
  this.readers = CacheBuilder.newBuilder().build(new CacheLoader<Schema, GenericDatumReader<GenericRecord>>() {
    @Override
    public GenericDatumReader<GenericRecord> load(final Schema key) throws Exception {
      return new GenericDatumReader<>(key);
    }
  });
  return this;
}
 
Example 4
Source File: Avro16Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public BinaryDecoder newBinaryDecoder(InputStream in, boolean buffered, BinaryDecoder reuse) {
  DecoderFactory factory = DecoderFactory.get();
  return buffered ? factory.binaryDecoder(in, reuse) : factory.directBinaryDecoder(in, reuse);
}
 
Example 5
Source File: Avro15Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public BinaryDecoder newBinaryDecoder(InputStream in, boolean buffered, BinaryDecoder reuse) {
  DecoderFactory factory = DecoderFactory.get();
  return buffered ? factory.binaryDecoder(in, reuse) : factory.directBinaryDecoder(in, reuse);
}
 
Example 6
Source File: Avro18Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public BinaryDecoder newBinaryDecoder(InputStream in, boolean buffered, BinaryDecoder reuse) {
  DecoderFactory factory = DecoderFactory.get();
  return buffered ? factory.binaryDecoder(in, reuse) : factory.directBinaryDecoder(in, reuse);
}
 
Example 7
Source File: Avro19Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public BinaryDecoder newBinaryDecoder(InputStream in, boolean buffered, BinaryDecoder reuse) {
  DecoderFactory factory = DecoderFactory.get();
  return buffered ? factory.binaryDecoder(in, reuse) : factory.directBinaryDecoder(in, reuse);
}
 
Example 8
Source File: Avro17Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public BinaryDecoder newBinaryDecoder(InputStream in, boolean buffered, BinaryDecoder reuse) {
  DecoderFactory factory = DecoderFactory.get();
  return buffered ? factory.binaryDecoder(in, reuse) : factory.directBinaryDecoder(in, reuse);
}