Examples of IncrementalIndex


Examples of io.druid.segment.incremental.IncrementalIndex

      final Interval interval = config.getGranularitySpec().bucketInterval(bucket.time).get();
      //final DataRollupSpec rollupSpec = config.getRollupSpec();
      final AggregatorFactory[] aggs = config.getSchema().getDataSchema().getAggregators();

      IncrementalIndex index = makeIncrementalIndex(bucket, aggs);
      try {
        File baseFlushFile = File.createTempFile("base", "flush");
        baseFlushFile.delete();
        baseFlushFile.mkdirs();

        Set<File> toMerge = Sets.newTreeSet();
        int indexCount = 0;
        int lineCount = 0;
        int runningTotalLineCount = 0;
        long startTime = System.currentTimeMillis();

        Set<String> allDimensionNames = Sets.newHashSet();
        final ProgressIndicator progressIndicator = makeProgressIndicator(context);

        for (final Text value : values) {
          context.progress();
          final InputRow inputRow = index.formatRow(parser.parse(value.toString()));
          allDimensionNames.addAll(inputRow.getDimensions());

          int numRows = index.add(inputRow);
          ++lineCount;

          if (numRows >= config.getSchema().getTuningConfig().getRowFlushBoundary()) {
            log.info(
                "%,d lines to %,d rows in %,d millis",
                lineCount - runningTotalLineCount,
                numRows,
                System.currentTimeMillis() - startTime
            );
            runningTotalLineCount = lineCount;

            final File file = new File(baseFlushFile, String.format("index%,05d", indexCount));
            toMerge.add(file);

            context.progress();
            persist(index, interval, file, progressIndicator);
            // close this index and make a new one
            index.close();
            index = makeIncrementalIndex(bucket, aggs);

            startTime = System.currentTimeMillis();
            ++indexCount;
          }
        }

        log.info("%,d lines completed.", lineCount);

        List<QueryableIndex> indexes = Lists.newArrayListWithCapacity(indexCount);
        final File mergedBase;

        if (toMerge.size() == 0) {
          if (index.isEmpty()) {
            throw new IAE("If you try to persist empty indexes you are going to have a bad time");
          }

          mergedBase = new File(baseFlushFile, "merged");
          persist(index, interval, mergedBase, progressIndicator);
        } else {
          if (!index.isEmpty()) {
            final File finalFile = new File(baseFlushFile, "final");
            persist(index, interval, finalFile, progressIndicator);
            toMerge.add(finalFile);
          }

          for (File file : toMerge) {
            indexes.add(IndexIO.loadIndex(file));
          }
          mergedBase = mergeQueryableIndex(
              indexes, aggs, new File(baseFlushFile, "merged"), progressIndicator
          );
        }
        serializeOutIndex(context, bucket, mergedBase, Lists.newArrayList(allDimensionNames));
        for (File file : toMerge) {
          FileUtils.deleteDirectory(file);
        }
      }
      finally {
        index.close();
      }
    }
View Full Code Here

Examples of io.druid.segment.incremental.IncrementalIndex

        return new OffheapIncrementalIndex(
            indexSchema,
            new OffheapBufferPool(bufferSize)
        );
      } else {
        return new IncrementalIndex(
            indexSchema,
            new OffheapBufferPool(bufferSize)
        );
      }
    }
View Full Code Here

Examples of io.druid.segment.incremental.IncrementalIndex

          .build();

      final GroupByQuery outerQuery = new GroupByQuery.Builder(query)
          .setLimitSpec(query.getLimitSpec().merge(subquery.getLimitSpec()))
          .build();
      IncrementalIndex index = makeIncrementalIndex(innerQuery, subqueryResult);

      return new ResourceClosingSequence<>(
          outerQuery.applyLimit(
              engine.process(
                  outerQuery,
                  new IncrementalIndexStorageAdapter(
                      index
                  )
              )
          ),
          index
      );
    } else {
      final IncrementalIndex index = makeIncrementalIndex(query, runner.run(query, context));
      return new ResourceClosingSequence<>(query.applyLimit(postAggregate(query, index)), index);
    }
  }
View Full Code Here

Examples of io.druid.segment.incremental.IncrementalIndex

public class TimeseriesQueryRunnerBonusTest
{
  @Test
  public void testOneRowAtATime() throws Exception
  {
    final IncrementalIndex oneRowIndex = new IncrementalIndex(
        new DateTime("2012-01-01T00:00:00Z").getMillis(), QueryGranularity.NONE, new AggregatorFactory[]{},
        TestQueryRunners.pool
    );

    List<Result<TimeseriesResultValue>> results;

    oneRowIndex.add(
        new MapBasedInputRow(
            new DateTime("2012-01-01T00:00:00Z").getMillis(),
            ImmutableList.of("dim1"),
            ImmutableMap.<String, Object>of("dim1", "x")
        )
    );

    results = runTimeseriesCount(oneRowIndex);

    Assert.assertEquals("index size", 1, oneRowIndex.size());
    Assert.assertEquals("result size", 1, results.size());
    Assert.assertEquals("result timestamp", new DateTime("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
    Assert.assertEquals("result count metric", 1, (long) results.get(0).getValue().getLongMetric("rows"));

    oneRowIndex.add(
        new MapBasedInputRow(
            new DateTime("2012-01-01T00:00:00Z").getMillis(),
            ImmutableList.of("dim1"),
            ImmutableMap.<String, Object>of("dim1", "y")
        )
    );

    results = runTimeseriesCount(oneRowIndex);

    Assert.assertEquals("index size", 2, oneRowIndex.size());
    Assert.assertEquals("result size", 1, results.size());
    Assert.assertEquals("result timestamp", new DateTime("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
    Assert.assertEquals("result count metric", 2, (long) results.get(0).getValue().getLongMetric("rows"));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.