Search in sources :

Example 1 with ByteEntity

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

the class ProtobufInputFormatTest method testParseNestedData.

@Test
public void testParseNestedData() throws Exception {
    // configure parser with desc file
    ProtobufInputFormat protobufInputFormat = new ProtobufInputFormat(flattenSpec, decoder);
    // create binary of proto test event
    DateTime dateTime = new DateTime(2012, 7, 12, 9, 30, ISOChronology.getInstanceUTC());
    ProtoTestEventWrapper.ProtoTestEvent event = ProtobufInputRowParserTest.buildNestedData(dateTime);
    final ByteEntity entity = new ByteEntity(ProtobufInputRowParserTest.toByteBuffer(event));
    InputRow row = protobufInputFormat.createReader(new InputRowSchema(timestampSpec, dimensionsSpec, null), entity, null).read().next();
    ProtobufInputRowParserTest.verifyNestedData(row, dateTime);
}
Also used : ByteEntity(org.apache.druid.data.input.impl.ByteEntity) InputRow(org.apache.druid.data.input.InputRow) InputRowSchema(org.apache.druid.data.input.InputRowSchema) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with ByteEntity

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

the class ProtobufInputFormatTest method testParseFlatData.

@Test
public void testParseFlatData() throws Exception {
    // configure parser with desc file
    ProtobufInputFormat protobufInputFormat = new ProtobufInputFormat(null, decoder);
    // create binary of proto test event
    DateTime dateTime = new DateTime(2012, 7, 12, 9, 30, ISOChronology.getInstanceUTC());
    ProtoTestEventWrapper.ProtoTestEvent event = ProtobufInputRowParserTest.buildFlatData(dateTime);
    final ByteEntity entity = new ByteEntity(ProtobufInputRowParserTest.toByteBuffer(event));
    InputRow row = protobufInputFormat.createReader(new InputRowSchema(timestampSpec, dimensionsSpec, null), entity, null).read().next();
    ProtobufInputRowParserTest.verifyFlatData(row, dateTime);
}
Also used : ByteEntity(org.apache.druid.data.input.impl.ByteEntity) InputRow(org.apache.druid.data.input.InputRow) InputRowSchema(org.apache.druid.data.input.InputRowSchema) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with ByteEntity

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

the class StreamChunkParserTest method testWithParserAndNullInputformatParseProperly.

@Test
public void testWithParserAndNullInputformatParseProperly() throws IOException {
    final InputRowParser<ByteBuffer> parser = new StringInputRowParser(new JSONParseSpec(TIMESTAMP_SPEC, DimensionsSpec.EMPTY, JSONPathSpec.DEFAULT, Collections.emptyMap(), false), StringUtils.UTF8_STRING);
    final StreamChunkParser<ByteEntity> chunkParser = new StreamChunkParser<>(parser, // Set nulls for all parameters below since inputFormat will be never used.
    null, null, null, null, row -> true, rowIngestionMeters, parseExceptionHandler);
    parseAndAssertResult(chunkParser);
}
Also used : ByteEntity(org.apache.druid.data.input.impl.ByteEntity) StringInputRowParser(org.apache.druid.data.input.impl.StringInputRowParser) ByteBuffer(java.nio.ByteBuffer) JSONParseSpec(org.apache.druid.data.input.impl.JSONParseSpec) Test(org.junit.Test)

Example 4 with ByteEntity

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

the class StreamChunkParserTest method testWithNullParserAndInputformatParseProperly.

@Test
public void testWithNullParserAndInputformatParseProperly() throws IOException {
    final JsonInputFormat inputFormat = new JsonInputFormat(JSONPathSpec.DEFAULT, Collections.emptyMap(), null);
    final StreamChunkParser<ByteEntity> chunkParser = new StreamChunkParser<>(null, inputFormat, new InputRowSchema(TIMESTAMP_SPEC, DimensionsSpec.EMPTY, ColumnsFilter.all()), TransformSpec.NONE, temporaryFolder.newFolder(), row -> true, rowIngestionMeters, parseExceptionHandler);
    parseAndAssertResult(chunkParser);
}
Also used : JsonInputFormat(org.apache.druid.data.input.impl.JsonInputFormat) ByteEntity(org.apache.druid.data.input.impl.ByteEntity) InputRowSchema(org.apache.druid.data.input.InputRowSchema) Test(org.junit.Test)

Example 5 with ByteEntity

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

the class StreamChunkParserTest method parseAndAssertResult.

private void parseAndAssertResult(StreamChunkParser<ByteEntity> chunkParser) throws IOException {
    final String json = "{\"timestamp\": \"2020-01-01\", \"dim\": \"val\", \"met\": \"val2\"}";
    List<InputRow> parsedRows = chunkParser.parse(Collections.singletonList(new ByteEntity(json.getBytes(StringUtils.UTF8_STRING))), false);
    Assert.assertEquals(1, parsedRows.size());
    InputRow row = parsedRows.get(0);
    Assert.assertEquals(DateTimes.of("2020-01-01"), row.getTimestamp());
    Assert.assertEquals("val", Iterables.getOnlyElement(row.getDimension("dim")));
    Assert.assertEquals("val2", Iterables.getOnlyElement(row.getDimension("met")));
}
Also used : ByteEntity(org.apache.druid.data.input.impl.ByteEntity) InputRow(org.apache.druid.data.input.InputRow)

Aggregations

ByteEntity (org.apache.druid.data.input.impl.ByteEntity)13 Test (org.junit.Test)10 InputRowSchema (org.apache.druid.data.input.InputRowSchema)7 InputRow (org.apache.druid.data.input.InputRow)5 ByteBuffer (java.nio.ByteBuffer)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Schema (org.apache.avro.Schema)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)2 AvroStreamInputFormat (org.apache.druid.data.input.avro.AvroStreamInputFormat)2 JSONParseSpec (org.apache.druid.data.input.impl.JSONParseSpec)2 NestedInputFormat (org.apache.druid.data.input.impl.NestedInputFormat)2 StringInputRowParser (org.apache.druid.data.input.impl.StringInputRowParser)2 Avro1124SubjectAndIdConverter (org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter)2 NoopRowIngestionMeters (org.apache.druid.segment.incremental.NoopRowIngestionMeters)2 RowIngestionMeters (org.apache.druid.segment.incremental.RowIngestionMeters)2 DateTime (org.joda.time.DateTime)2 Before (org.junit.Before)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1