Search in sources :

Example 16 with IndexSpec

use of io.druid.segment.IndexSpec in project druid by druid-io.

the class HadoopConverterJobTest method testSimpleJob.

@Test
public void testSimpleJob() throws IOException, InterruptedException {
    final SQLMetadataSegmentManager manager = new SQLMetadataSegmentManager(HadoopDruidConverterConfig.jsonMapper, new Supplier<MetadataSegmentManagerConfig>() {

        @Override
        public MetadataSegmentManagerConfig get() {
            return new MetadataSegmentManagerConfig();
        }
    }, metadataStorageTablesConfigSupplier, connector);
    final List<DataSegment> oldSemgments = getDataSegments(manager);
    final File tmpDir = temporaryFolder.newFolder();
    final HadoopConverterJob converterJob = new HadoopConverterJob(new HadoopDruidConverterConfig(DATASOURCE, interval, new IndexSpec(new RoaringBitmapSerdeFactory(null), CompressedObjectStrategy.CompressionStrategy.UNCOMPRESSED, CompressedObjectStrategy.CompressionStrategy.UNCOMPRESSED, CompressionFactory.LongEncodingStrategy.LONGS), oldSemgments, true, tmpDir.toURI(), ImmutableMap.<String, String>of(), null, tmpSegmentDir.toURI().toString()));
    final List<DataSegment> segments = Lists.newArrayList(converterJob.run());
    Assert.assertNotNull("bad result", segments);
    Assert.assertEquals("wrong segment count", 4, segments.size());
    Assert.assertTrue(converterJob.getLoadedBytes() > 0);
    Assert.assertTrue(converterJob.getWrittenBytes() > 0);
    Assert.assertTrue(converterJob.getWrittenBytes() > converterJob.getLoadedBytes());
    Assert.assertEquals(oldSemgments.size(), segments.size());
    final DataSegment segment = segments.get(0);
    Assert.assertTrue(interval.contains(segment.getInterval()));
    Assert.assertTrue(segment.getVersion().endsWith("_converted"));
    Assert.assertTrue(segment.getLoadSpec().get("path").toString().contains("_converted"));
    for (File file : tmpDir.listFiles()) {
        Assert.assertFalse(file.isDirectory());
        Assert.assertTrue(file.isFile());
    }
    final Comparator<DataSegment> segmentComparator = new Comparator<DataSegment>() {

        @Override
        public int compare(DataSegment o1, DataSegment o2) {
            return o1.getIdentifier().compareTo(o2.getIdentifier());
        }
    };
    Collections.sort(oldSemgments, segmentComparator);
    Collections.sort(segments, segmentComparator);
    for (int i = 0; i < oldSemgments.size(); ++i) {
        final DataSegment oldSegment = oldSemgments.get(i);
        final DataSegment newSegment = segments.get(i);
        Assert.assertEquals(oldSegment.getDataSource(), newSegment.getDataSource());
        Assert.assertEquals(oldSegment.getInterval(), newSegment.getInterval());
        Assert.assertEquals(Sets.<String>newHashSet(oldSegment.getMetrics()), Sets.<String>newHashSet(newSegment.getMetrics()));
        Assert.assertEquals(Sets.<String>newHashSet(oldSegment.getDimensions()), Sets.<String>newHashSet(newSegment.getDimensions()));
        Assert.assertEquals(oldSegment.getVersion() + "_converted", newSegment.getVersion());
        Assert.assertTrue(oldSegment.getSize() < newSegment.getSize());
        Assert.assertEquals(oldSegment.getBinaryVersion(), newSegment.getBinaryVersion());
    }
}
Also used : IndexSpec(io.druid.segment.IndexSpec) DataSegment(io.druid.timeline.DataSegment) Comparator(java.util.Comparator) MetadataSegmentManagerConfig(io.druid.metadata.MetadataSegmentManagerConfig) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) SQLMetadataSegmentManager(io.druid.metadata.SQLMetadataSegmentManager) File(java.io.File) Test(org.junit.Test)

Example 17 with IndexSpec

use of io.druid.segment.IndexSpec in project druid by druid-io.

the class HadoopConverterJobTest method testHadoopFailure.

@Test
// This takes a long time due to retries
@Ignore
public void testHadoopFailure() throws IOException, InterruptedException {
    final SQLMetadataSegmentManager manager = new SQLMetadataSegmentManager(HadoopDruidConverterConfig.jsonMapper, new Supplier<MetadataSegmentManagerConfig>() {

        @Override
        public MetadataSegmentManagerConfig get() {
            return new MetadataSegmentManagerConfig();
        }
    }, metadataStorageTablesConfigSupplier, connector);
    final List<DataSegment> oldSemgments = getDataSegments(manager);
    final File tmpDir = temporaryFolder.newFolder();
    final HadoopConverterJob converterJob = new HadoopConverterJob(new HadoopDruidConverterConfig(DATASOURCE, interval, new IndexSpec(new RoaringBitmapSerdeFactory(null), CompressedObjectStrategy.CompressionStrategy.UNCOMPRESSED, CompressedObjectStrategy.CompressionStrategy.UNCOMPRESSED, CompressionFactory.LongEncodingStrategy.LONGS), oldSemgments, true, tmpDir.toURI(), ImmutableMap.<String, String>of(), null, tmpSegmentDir.toURI().toString()));
    corrupt(oldSemgments.get(0));
    final List<DataSegment> result = converterJob.run();
    Assert.assertNull("result should be null", result);
    final List<DataSegment> segments = getDataSegments(manager);
    Assert.assertEquals(oldSemgments.size(), segments.size());
    Assert.assertEquals(oldSemgments, segments);
}
Also used : MetadataSegmentManagerConfig(io.druid.metadata.MetadataSegmentManagerConfig) IndexSpec(io.druid.segment.IndexSpec) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) SQLMetadataSegmentManager(io.druid.metadata.SQLMetadataSegmentManager) DataSegment(io.druid.timeline.DataSegment) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with IndexSpec

use of io.druid.segment.IndexSpec in project druid by druid-io.

the class HadoopDruidConverterConfigTest method simpleSerDe.

@Test
public void simpleSerDe() throws IOException {
    final HadoopDruidConverterConfig config = new HadoopDruidConverterConfig("datasource", Interval.parse("2000/2010"), new IndexSpec(), ImmutableList.<DataSegment>of(), true, URI.create("file:/dev/null"), ImmutableMap.<String, String>of(), "HIGH", temporaryFolder.newFolder().getAbsolutePath());
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.registerSubtypes(HadoopDruidConverterConfig.class);
    final byte[] value = mapper.writeValueAsBytes(config);
    final HadoopDruidConverterConfig config2 = mapper.readValue(value, HadoopDruidConverterConfig.class);
    Assert.assertEquals(mapper.writeValueAsString(config), mapper.writeValueAsString(config2));
}
Also used : IndexSpec(io.druid.segment.IndexSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 19 with IndexSpec

use of io.druid.segment.IndexSpec in project druid by druid-io.

the class HadoopTuningConfigTest method testSerde.

@Test
public void testSerde() throws Exception {
    HadoopTuningConfig expected = new HadoopTuningConfig("/tmp/workingpath", "version", null, null, null, 100, true, true, true, true, null, true, true, null, null, null, true, true);
    HadoopTuningConfig actual = jsonReadWriteRead(jsonMapper.writeValueAsString(expected), HadoopTuningConfig.class);
    Assert.assertEquals("/tmp/workingpath", actual.getWorkingPath());
    Assert.assertEquals("version", actual.getVersion());
    Assert.assertNotNull(actual.getPartitionsSpec());
    Assert.assertEquals(ImmutableMap.<DateTime, List<HadoopyShardSpec>>of(), actual.getShardSpecs());
    Assert.assertEquals(new IndexSpec(), actual.getIndexSpec());
    Assert.assertEquals(100, actual.getRowFlushBoundary());
    Assert.assertEquals(true, actual.isLeaveIntermediate());
    Assert.assertEquals(true, actual.isCleanupOnFailure());
    Assert.assertEquals(true, actual.isOverwriteFiles());
    Assert.assertEquals(true, actual.isIgnoreInvalidRows());
    Assert.assertEquals(ImmutableMap.<String, String>of(), actual.getJobProperties());
    Assert.assertEquals(true, actual.isCombineText());
    Assert.assertEquals(true, actual.getUseCombiner());
    Assert.assertEquals(0, actual.getNumBackgroundPersistThreads());
    Assert.assertEquals(true, actual.isForceExtendableShardSpecs());
    Assert.assertEquals(true, actual.isUseExplicitVersion());
}
Also used : IndexSpec(io.druid.segment.IndexSpec) Test(org.junit.Test)

Example 20 with IndexSpec

use of io.druid.segment.IndexSpec in project druid by druid-io.

the class RealtimePlumber method persistHydrant.

/**
   * Persists the given hydrant and returns the number of rows persisted
   *
   * @param indexToPersist hydrant to persist
   * @param schema         datasource schema
   * @param interval       interval to persist
   *
   * @return the number of rows persisted
   */
protected int persistHydrant(FireHydrant indexToPersist, DataSchema schema, Interval interval, Map<String, Object> metadataElems) {
    synchronized (indexToPersist) {
        if (indexToPersist.hasSwapped()) {
            log.info("DataSource[%s], Interval[%s], Hydrant[%s] already swapped. Ignoring request to persist.", schema.getDataSource(), interval, indexToPersist);
            return 0;
        }
        log.info("DataSource[%s], Interval[%s], Metadata [%s] persisting Hydrant[%s]", schema.getDataSource(), interval, metadataElems, indexToPersist);
        try {
            int numRows = indexToPersist.getIndex().size();
            final IndexSpec indexSpec = config.getIndexSpec();
            indexToPersist.getIndex().getMetadata().putAll(metadataElems);
            final File persistedFile = indexMerger.persist(indexToPersist.getIndex(), interval, new File(computePersistDir(schema, interval), String.valueOf(indexToPersist.getCount())), indexSpec);
            indexToPersist.swapSegment(new QueryableIndexSegment(indexToPersist.getSegment().getIdentifier(), indexIO.loadIndex(persistedFile)));
            return numRows;
        } catch (IOException e) {
            log.makeAlert("dataSource[%s] -- incremental persist failed", schema.getDataSource()).addData("interval", interval).addData("count", indexToPersist.getCount()).emit();
            throw Throwables.propagate(e);
        }
    }
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) IndexSpec(io.druid.segment.IndexSpec) IOException(java.io.IOException) File(java.io.File)

Aggregations

IndexSpec (io.druid.segment.IndexSpec)37 File (java.io.File)21 OnheapIncrementalIndex (io.druid.segment.incremental.OnheapIncrementalIndex)15 IncrementalIndex (io.druid.segment.incremental.IncrementalIndex)13 InputRow (io.druid.data.input.InputRow)11 Test (org.junit.Test)11 BenchmarkDataGenerator (io.druid.benchmark.datagen.BenchmarkDataGenerator)10 HyperUniquesSerde (io.druid.query.aggregation.hyperloglog.HyperUniquesSerde)10 QueryableIndex (io.druid.segment.QueryableIndex)10 Setup (org.openjdk.jmh.annotations.Setup)10 Period (org.joda.time.Period)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)5 StupidPool (io.druid.collections.StupidPool)4 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)4 OffheapBufferGenerator (io.druid.offheap.OffheapBufferGenerator)4 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)4 RoaringBitmapSerdeFactory (io.druid.segment.data.RoaringBitmapSerdeFactory)4 DataSegment (io.druid.timeline.DataSegment)4 IOException (java.io.IOException)4