Search in sources :

Example 1 with ByteBufferInputRowParser

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

the class InputRowParserSerdeTest method testCharsetParseHelper.

private InputRow testCharsetParseHelper(Charset charset) throws Exception {
    final StringInputRowParser parser = new StringInputRowParser(new JSONParseSpec(new TimestampSpec("timestamp", "iso", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("foo", "bar"))), null, null, null), charset.name());
    final ByteBufferInputRowParser parser2 = jsonMapper.readValue(jsonMapper.writeValueAsBytes(parser), ByteBufferInputRowParser.class);
    final InputRow parsed = parser2.parseBatch(ByteBuffer.wrap("{\"foo\":\"x\",\"bar\":\"y\",\"qux\":\"z\",\"timestamp\":\"3000\"}".getBytes(charset))).get(0);
    return parsed;
}
Also used : ByteBufferInputRowParser(org.apache.druid.data.input.ByteBufferInputRowParser) InputRow(org.apache.druid.data.input.InputRow)

Example 2 with ByteBufferInputRowParser

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

the class InputRowParserSerdeTest method testStringInputRowParserSerde.

@Test
public void testStringInputRowParserSerde() throws Exception {
    final StringInputRowParser parser = new StringInputRowParser(new JSONParseSpec(new TimestampSpec("timestamp", "iso", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("foo", "bar"))), null, null, null), null);
    final ByteBufferInputRowParser parser2 = jsonMapper.readValue(jsonMapper.writeValueAsBytes(parser), ByteBufferInputRowParser.class);
    final InputRow parsed = parser2.parseBatch(ByteBuffer.wrap(StringUtils.toUtf8("{\"foo\":\"x\",\"bar\":\"y\",\"qux\":\"z\",\"timestamp\":\"2000\"}"))).get(0);
    Assert.assertEquals(ImmutableList.of("foo", "bar"), parsed.getDimensions());
    Assert.assertEquals(ImmutableList.of("x"), parsed.getDimension("foo"));
    Assert.assertEquals(ImmutableList.of("y"), parsed.getDimension("bar"));
    Assert.assertEquals(DateTimes.of("2000").getMillis(), parsed.getTimestampFromEpoch());
}
Also used : ByteBufferInputRowParser(org.apache.druid.data.input.ByteBufferInputRowParser) InputRow(org.apache.druid.data.input.InputRow) Test(org.junit.Test)

Aggregations

ByteBufferInputRowParser (org.apache.druid.data.input.ByteBufferInputRowParser)2 InputRow (org.apache.druid.data.input.InputRow)2 Test (org.junit.Test)1