Search in sources :

Example 11 with TimeAndDimsParseSpec

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

the class SqlFirehoseTest method setup.

@Before
public void setup() throws IOException {
    TEST_DIR = File.createTempFile(SqlFirehose.class.getSimpleName(), "testDir");
    org.apache.commons.io.FileUtils.forceDelete(TEST_DIR);
    FileUtils.mkdirp(TEST_DIR);
    final List<Map<String, Object>> inputTexts = ImmutableList.of(ImmutableMap.of("x", "foostring1", "timestamp", 2000), ImmutableMap.of("x", "foostring2", "timestamp", 2000));
    List<FileInputStream> testFile = new ArrayList<>();
    this.objectMapper = new ObjectMapper(new SmileFactory());
    int i = 0;
    for (Map m : inputTexts) {
        File file = new File(TEST_DIR, "test_" + i++);
        try (FileOutputStream fos = new FileOutputStream(file)) {
            final JsonGenerator jg = objectMapper.getFactory().createGenerator(fos);
            jg.writeStartArray();
            jg.writeObject(m);
            jg.writeEndArray();
            jg.close();
            testFile.add(new FileInputStream(file));
        }
    }
    this.fileList = testFile;
    parser = TransformSpec.NONE.decorate(new MapInputRowParser(new TimeAndDimsParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("x"))))));
    this.inputs = inputTexts;
}
Also used : MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) TimeAndDimsParseSpec(org.apache.druid.data.input.impl.TimeAndDimsParseSpec) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) FileOutputStream(java.io.FileOutputStream) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

TimeAndDimsParseSpec (org.apache.druid.data.input.impl.TimeAndDimsParseSpec)11 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)11 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)10 MapInputRowParser (org.apache.druid.data.input.impl.MapInputRowParser)10 Map (java.util.Map)6 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)6 DataSchema (org.apache.druid.segment.indexing.DataSchema)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 InputRowParser (org.apache.druid.data.input.impl.InputRowParser)5 List (java.util.List)4 InputRow (org.apache.druid.data.input.InputRow)4 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)4 RealtimeTuningConfig (org.apache.druid.segment.indexing.RealtimeTuningConfig)4 UniformGranularitySpec (org.apache.druid.segment.indexing.granularity.UniformGranularitySpec)4 Before (org.junit.Before)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3