Search in sources :

Example 1 with NestedInputFormat

use of org.apache.druid.data.input.impl.NestedInputFormat in project druid by druid-io.

the class ProtobufInputFormatTest method testSerde.

@Test
public void testSerde() throws IOException {
    ProtobufInputFormat inputFormat = new ProtobufInputFormat(flattenSpec, decoder);
    NestedInputFormat inputFormat2 = jsonMapper.readValue(jsonMapper.writeValueAsString(inputFormat), NestedInputFormat.class);
    Assert.assertEquals(inputFormat, inputFormat2);
}
Also used : NestedInputFormat(org.apache.druid.data.input.impl.NestedInputFormat) Test(org.junit.Test)

Example 2 with NestedInputFormat

use of org.apache.druid.data.input.impl.NestedInputFormat in project druid by druid-io.

the class AvroStreamInputFormatTest method testSerdeNonDefault.

@Test
public void testSerdeNonDefault() throws IOException {
    Repository repository = new Avro1124RESTRepositoryClientWrapper("http://github.io");
    AvroStreamInputFormat inputFormat = new AvroStreamInputFormat(flattenSpec, new SchemaRepoBasedAvroBytesDecoder<>(new Avro1124SubjectAndIdConverter(TOPIC), repository), true, true);
    NestedInputFormat inputFormat2 = jsonMapper.readValue(jsonMapper.writeValueAsString(inputFormat), NestedInputFormat.class);
    Assert.assertEquals(inputFormat, inputFormat2);
}
Also used : Avro1124SubjectAndIdConverter(org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter) NestedInputFormat(org.apache.druid.data.input.impl.NestedInputFormat) Repository(org.schemarepo.Repository) InMemoryRepository(org.schemarepo.InMemoryRepository) TypedSchemaRepository(org.schemarepo.api.TypedSchemaRepository) Avro1124RESTRepositoryClientWrapper(org.apache.druid.data.input.schemarepo.Avro1124RESTRepositoryClientWrapper) AvroStreamInputFormat(org.apache.druid.data.input.avro.AvroStreamInputFormat) Test(org.junit.Test)

Example 3 with NestedInputFormat

use of org.apache.druid.data.input.impl.NestedInputFormat in project druid by druid-io.

the class AvroStreamInputFormatTest method testSerde.

@Test
public void testSerde() throws IOException {
    Repository repository = new Avro1124RESTRepositoryClientWrapper("http://github.io");
    AvroStreamInputFormat inputFormat = new AvroStreamInputFormat(flattenSpec, new SchemaRepoBasedAvroBytesDecoder<>(new Avro1124SubjectAndIdConverter(TOPIC), repository), false, false);
    NestedInputFormat inputFormat2 = jsonMapper.readValue(jsonMapper.writeValueAsString(inputFormat), NestedInputFormat.class);
    Assert.assertEquals(inputFormat, inputFormat2);
}
Also used : Avro1124SubjectAndIdConverter(org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter) NestedInputFormat(org.apache.druid.data.input.impl.NestedInputFormat) Repository(org.schemarepo.Repository) InMemoryRepository(org.schemarepo.InMemoryRepository) TypedSchemaRepository(org.schemarepo.api.TypedSchemaRepository) Avro1124RESTRepositoryClientWrapper(org.apache.druid.data.input.schemarepo.Avro1124RESTRepositoryClientWrapper) AvroStreamInputFormat(org.apache.druid.data.input.avro.AvroStreamInputFormat) Test(org.junit.Test)

Example 4 with NestedInputFormat

use of org.apache.druid.data.input.impl.NestedInputFormat in project druid by druid-io.

the class AvroStreamInputFormatTest method testParse.

@Test
public void testParse() throws SchemaValidationException, IOException {
    Repository repository = new InMemoryRepository(null);
    AvroStreamInputFormat inputFormat = new AvroStreamInputFormat(flattenSpec, new SchemaRepoBasedAvroBytesDecoder<>(new Avro1124SubjectAndIdConverter(TOPIC), repository), false, false);
    NestedInputFormat inputFormat2 = jsonMapper.readValue(jsonMapper.writeValueAsString(inputFormat), NestedInputFormat.class);
    repository = ((SchemaRepoBasedAvroBytesDecoder) ((AvroStreamInputFormat) inputFormat2).getAvroBytesDecoder()).getSchemaRepository();
    // prepare data
    GenericRecord someAvroDatum = buildSomeAvroDatum();
    // encode schema id
    Avro1124SubjectAndIdConverter converter = new Avro1124SubjectAndIdConverter(TOPIC);
    TypedSchemaRepository<Integer, Schema, String> repositoryClient = new TypedSchemaRepository<>(repository, new IntegerConverter(), new AvroSchemaConverter(), new IdentityConverter());
    Integer id = repositoryClient.registerSchema(TOPIC, SomeAvroDatum.getClassSchema());
    ByteBuffer byteBuffer = ByteBuffer.allocate(4);
    converter.putSubjectAndId(id, byteBuffer);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(byteBuffer.array());
    // encode data
    DatumWriter<GenericRecord> writer = new SpecificDatumWriter<>(someAvroDatum.getSchema());
    // write avro datum to bytes
    writer.write(someAvroDatum, EncoderFactory.get().directBinaryEncoder(out, null));
    final ByteEntity entity = new ByteEntity(ByteBuffer.wrap(out.toByteArray()));
    InputRow inputRow = inputFormat2.createReader(new InputRowSchema(timestampSpec, dimensionsSpec, null), entity, null).read().next();
    assertInputRowCorrect(inputRow, DIMENSIONS, false);
}
Also used : Avro1124SubjectAndIdConverter(org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter) NestedInputFormat(org.apache.druid.data.input.impl.NestedInputFormat) AvroSchemaConverter(org.schemarepo.api.converter.AvroSchemaConverter) InMemoryRepository(org.schemarepo.InMemoryRepository) TypedSchemaRepository(org.schemarepo.api.TypedSchemaRepository) ByteEntity(org.apache.druid.data.input.impl.ByteEntity) Schema(org.apache.avro.Schema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter) IntegerConverter(org.schemarepo.api.converter.IntegerConverter) Repository(org.schemarepo.Repository) InMemoryRepository(org.schemarepo.InMemoryRepository) TypedSchemaRepository(org.schemarepo.api.TypedSchemaRepository) IdentityConverter(org.schemarepo.api.converter.IdentityConverter) GenericRecord(org.apache.avro.generic.GenericRecord) AvroStreamInputFormat(org.apache.druid.data.input.avro.AvroStreamInputFormat) Test(org.junit.Test)

Example 5 with NestedInputFormat

use of org.apache.druid.data.input.impl.NestedInputFormat in project druid by druid-io.

the class AvroOCFInputFormatTest method testSerdeNonDefaults.

@Test
public void testSerdeNonDefaults() throws Exception {
    String schemaStr = "{\n" + "  \"namespace\": \"org.apache.druid.data.input\",\n" + "  \"name\": \"SomeAvroDatum\",\n" + "  \"type\": \"record\",\n" + "  \"fields\" : [\n" + "    {\"name\":\"timestamp\",\"type\":\"long\"},\n" + "    {\"name\":\"someLong\",\"type\":\"long\"}\n," + "    {\"name\":\"eventClass\",\"type\":\"string\", \"aliases\": [\"eventType\"]}\n" + "  ]\n" + "}";
    TypeReference<Map<String, Object>> typeRef = new TypeReference<Map<String, Object>>() {
    };
    final Map<String, Object> readerSchema = jsonMapper.readValue(schemaStr, typeRef);
    AvroOCFInputFormat inputFormat = new AvroOCFInputFormat(jsonMapper, flattenSpec, readerSchema, true, true);
    NestedInputFormat inputFormat2 = jsonMapper.readValue(jsonMapper.writeValueAsString(inputFormat), NestedInputFormat.class);
    Assert.assertEquals(inputFormat, inputFormat2);
}
Also used : NestedInputFormat(org.apache.druid.data.input.impl.NestedInputFormat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) Test(org.junit.Test)

Aggregations

NestedInputFormat (org.apache.druid.data.input.impl.NestedInputFormat)9 Test (org.junit.Test)9 AvroStreamInputFormat (org.apache.druid.data.input.avro.AvroStreamInputFormat)5 Avro1124SubjectAndIdConverter (org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter)4 InMemoryRepository (org.schemarepo.InMemoryRepository)4 Repository (org.schemarepo.Repository)4 TypedSchemaRepository (org.schemarepo.api.TypedSchemaRepository)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Schema (org.apache.avro.Schema)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)2 ByteEntity (org.apache.druid.data.input.impl.ByteEntity)2 Avro1124RESTRepositoryClientWrapper (org.apache.druid.data.input.schemarepo.Avro1124RESTRepositoryClientWrapper)2 AvroSchemaConverter (org.schemarepo.api.converter.AvroSchemaConverter)2 IdentityConverter (org.schemarepo.api.converter.IdentityConverter)2 IntegerConverter (org.schemarepo.api.converter.IntegerConverter)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Map (java.util.Map)1 SchemaRegistryBasedAvroBytesDecoder (org.apache.druid.data.input.avro.SchemaRegistryBasedAvroBytesDecoder)1