Search in sources :

Example 51 with InputRow

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

the class ParquetReaderResourceLeakTest method testFetchOnReadCleanupAfterExhaustingIterator.

@Test
public void testFetchOnReadCleanupAfterExhaustingIterator() throws IOException {
    InputRowSchema schema = new InputRowSchema(new TimestampSpec("timestamp", "iso", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("page", "language", "user", "unpatrolled"))), ColumnsFilter.all());
    FetchingFileEntity entity = new FetchingFileEntity(new File("example/wiki/wiki.parquet"));
    ParquetInputFormat parquet = new ParquetInputFormat(JSONPathSpec.DEFAULT, false, new Configuration());
    File tempDir = temporaryFolder.newFolder();
    InputEntityReader reader = parquet.createReader(schema, entity, tempDir);
    Assert.assertEquals(0, Objects.requireNonNull(tempDir.list()).length);
    try (CloseableIterator<InputRow> iterator = reader.read()) {
        Assert.assertTrue(Objects.requireNonNull(tempDir.list()).length > 0);
        while (iterator.hasNext()) {
            iterator.next();
        }
    }
    Assert.assertEquals(0, Objects.requireNonNull(tempDir.list()).length);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) InputRow(org.apache.druid.data.input.InputRow) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) InputRowSchema(org.apache.druid.data.input.InputRowSchema) InputEntityReader(org.apache.druid.data.input.InputEntityReader) File(java.io.File) Test(org.junit.Test)

Example 52 with InputRow

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

the class ProtobufReaderTest method testParseFlatDataWithComplexTimestamp.

@Test
public void testParseFlatDataWithComplexTimestamp() throws Exception {
    ProtobufReader reader = new ProtobufReader(inputRowSchemaWithComplexTimestamp, null, decoder, null);
    // create binary of proto test event
    DateTime dateTime = new DateTime(2012, 7, 12, 9, 30, ISOChronology.getInstanceUTC());
    ProtoTestEventWrapper.ProtoTestEvent event = ProtobufInputRowParserTest.buildFlatDataWithComplexTimestamp(dateTime);
    ByteBuffer buffer = ProtobufInputRowParserTest.toByteBuffer(event);
    InputRow row = reader.parseInputRows(decoder.parse(buffer)).get(0);
    ProtobufInputRowParserTest.verifyFlatDataWithComplexTimestamp(row, dateTime);
}
Also used : InputRow(org.apache.druid.data.input.InputRow) ByteBuffer(java.nio.ByteBuffer) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 53 with InputRow

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

the class ProtobufReaderTest method testParseNestedData.

@Test
public void testParseNestedData() throws Exception {
    ProtobufReader reader = new ProtobufReader(inputRowSchema, null, decoder, flattenSpec);
    // create binary of proto test event
    DateTime dateTime = new DateTime(2012, 7, 12, 9, 30, ISOChronology.getInstanceUTC());
    ProtoTestEventWrapper.ProtoTestEvent event = ProtobufInputRowParserTest.buildNestedData(dateTime);
    ByteBuffer buffer = ProtobufInputRowParserTest.toByteBuffer(event);
    InputRow row = reader.parseInputRows(decoder.parse(buffer)).get(0);
    ProtobufInputRowParserTest.verifyNestedData(row, dateTime);
}
Also used : InputRow(org.apache.druid.data.input.InputRow) ByteBuffer(java.nio.ByteBuffer) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 54 with InputRow

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

the class ProtobufReaderTest method testParseFlatDataWithComplexTimestampWithDefaultFlattenSpec.

@Test
public void testParseFlatDataWithComplexTimestampWithDefaultFlattenSpec() throws Exception {
    expectedException.expect(ParseException.class);
    expectedException.expectMessage("is unparseable!");
    ProtobufReader reader = new ProtobufReader(inputRowSchemaWithComplexTimestamp, null, decoder, JSONPathSpec.DEFAULT);
    // create binary of proto test event
    DateTime dateTime = new DateTime(2012, 7, 12, 9, 30, ISOChronology.getInstanceUTC());
    ProtoTestEventWrapper.ProtoTestEvent event = ProtobufInputRowParserTest.buildFlatDataWithComplexTimestamp(dateTime);
    ByteBuffer buffer = ProtobufInputRowParserTest.toByteBuffer(event);
    InputRow row = reader.parseInputRows(decoder.parse(buffer)).get(0);
    ProtobufInputRowParserTest.verifyFlatDataWithComplexTimestamp(row, dateTime);
}
Also used : InputRow(org.apache.druid.data.input.InputRow) ByteBuffer(java.nio.ByteBuffer) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 55 with InputRow

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

the class TimestampsParquetInputTest method testDateHandling.

@Test
public void testDateHandling() throws IOException, InterruptedException {
    HadoopDruidIndexerConfig configTimeAsString = transformHadoopDruidIndexerConfig("example/timestamps/date_test_data_job_string.json", parserType, false);
    HadoopDruidIndexerConfig configTimeAsDate = transformHadoopDruidIndexerConfig("example/timestamps/date_test_data_job_date.json", parserType, false);
    List<InputRow> rowsWithString = getAllRows(parserType, configTimeAsString);
    List<InputRow> rowsWithDate = getAllRows(parserType, configTimeAsDate);
    Assert.assertEquals(rowsWithDate.size(), rowsWithString.size());
    for (int i = 0; i < rowsWithDate.size(); i++) {
        Assert.assertEquals(rowsWithString.get(i).getTimestamp(), rowsWithDate.get(i).getTimestamp());
    }
}
Also used : InputRow(org.apache.druid.data.input.InputRow) HadoopDruidIndexerConfig(org.apache.druid.indexer.HadoopDruidIndexerConfig) Test(org.junit.Test)

Aggregations

InputRow (org.apache.druid.data.input.InputRow)266 Test (org.junit.Test)193 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)57 InputEntityReader (org.apache.druid.data.input.InputEntityReader)54 InputRowSchema (org.apache.druid.data.input.InputRowSchema)52 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)52 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)49 ArrayList (java.util.ArrayList)46 List (java.util.List)37 ImmutableList (com.google.common.collect.ImmutableList)33 JSONPathSpec (org.apache.druid.java.util.common.parsers.JSONPathSpec)33 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)33 InputRowListPlusRawValues (org.apache.druid.data.input.InputRowListPlusRawValues)29 File (java.io.File)27 HadoopDruidIndexerConfig (org.apache.druid.indexer.HadoopDruidIndexerConfig)27 JSONPathFieldSpec (org.apache.druid.java.util.common.parsers.JSONPathFieldSpec)27 DateTime (org.joda.time.DateTime)24 Map (java.util.Map)23 IOException (java.io.IOException)18 Interval (org.joda.time.Interval)18