Search in sources :

Example 1 with HyperUniquesSerde

use of org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde in project druid by druid-io.

the class SegmentGenerator method generateIncrementalIndex.

public IncrementalIndex generateIncrementalIndex(final DataSegment dataSegment, final GeneratorSchemaInfo schemaInfo, final Granularity granularity, final int numRows) {
    // In case we need to generate hyperUniques.
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    final String dataHash = Hashing.sha256().newHasher().putString(dataSegment.getId().toString(), StandardCharsets.UTF_8).putString(schemaInfo.toString(), StandardCharsets.UTF_8).putString(granularity.toString(), StandardCharsets.UTF_8).putInt(numRows).hash().toString();
    final DataGenerator dataGenerator = new DataGenerator(schemaInfo.getColumnSchemas(), dataSegment.getId().hashCode(), /* Use segment identifier hashCode as seed */
    schemaInfo.getDataInterval(), numRows);
    final IncrementalIndexSchema indexSchema = new IncrementalIndexSchema.Builder().withDimensionsSpec(schemaInfo.getDimensionsSpec()).withMetrics(schemaInfo.getAggsArray()).withRollup(schemaInfo.isWithRollup()).withQueryGranularity(granularity).build();
    final List<InputRow> rows = new ArrayList<>();
    for (int i = 0; i < numRows; i++) {
        final InputRow row = dataGenerator.nextRow();
        rows.add(row);
        if ((i + 1) % 20000 == 0) {
            log.info("%,d/%,d rows generated for[%s].", i + 1, numRows, dataSegment);
        }
    }
    log.info("%,d/%,d rows generated for[%s].", numRows, numRows, dataSegment);
    return makeIncrementalIndex(dataSegment.getId(), dataHash, 0, rows, indexSchema);
}
Also used : InputRow(org.apache.druid.data.input.InputRow) ArrayList(java.util.ArrayList) HyperUniquesSerde(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde) IncrementalIndexSchema(org.apache.druid.segment.incremental.IncrementalIndexSchema)

Example 2 with HyperUniquesSerde

use of org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde in project druid by druid-io.

the class ComplexMetricsTest method testRegister.

@Test
public void testRegister() {
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    ComplexMetricSerde serde = ComplexMetrics.getSerdeForType("hyperUnique");
    Assert.assertNotNull(serde);
    Assert.assertTrue(serde instanceof HyperUniquesSerde);
}
Also used : HyperUniquesSerde(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde) Test(org.junit.Test)

Example 3 with HyperUniquesSerde

use of org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde in project druid by druid-io.

the class ComplexMetricsTest method testRegisterDuplicate.

@Test
public void testRegisterDuplicate() {
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    ComplexMetricSerde serde = ComplexMetrics.getSerdeForType("hyperUnique");
    Assert.assertNotNull(serde);
    Assert.assertTrue(serde instanceof HyperUniquesSerde);
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    serde = ComplexMetrics.getSerdeForType("hyperUnique");
    Assert.assertNotNull(serde);
    Assert.assertTrue(serde instanceof HyperUniquesSerde);
}
Also used : HyperUniquesSerde(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde) Test(org.junit.Test)

Example 4 with HyperUniquesSerde

use of org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde in project druid by druid-io.

the class ScanBenchmark method setup.

/**
 * Setup everything common for benchmarking both the incremental-index and the queriable-index.
 */
@Setup
public void setup() {
    log.info("SETUP CALLED AT " + +System.currentTimeMillis());
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    setupQueries();
    String[] schemaQuery = schemaAndQuery.split("\\.");
    String schemaName = schemaQuery[0];
    String queryName = schemaQuery[1];
    schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schemaName);
    queryBuilder = SCHEMA_QUERY_MAP.get(schemaName).get(queryName);
    queryBuilder.limit(limit);
    query = queryBuilder.build();
    generator = new DataGenerator(schemaInfo.getColumnSchemas(), System.currentTimeMillis(), schemaInfo.getDataInterval(), rowsPerSegment);
    final ScanQueryConfig config = new ScanQueryConfig().setLegacy(false);
    factory = new ScanQueryRunnerFactory(new ScanQueryQueryToolChest(config, DefaultGenericQueryMetricsFactory.instance()), new ScanQueryEngine(), new ScanQueryConfig());
}
Also used : ScanQueryConfig(org.apache.druid.query.scan.ScanQueryConfig) ScanQueryQueryToolChest(org.apache.druid.query.scan.ScanQueryQueryToolChest) DataGenerator(org.apache.druid.segment.generator.DataGenerator) HyperUniquesSerde(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde) ScanQueryEngine(org.apache.druid.query.scan.ScanQueryEngine) ScanQueryRunnerFactory(org.apache.druid.query.scan.ScanQueryRunnerFactory) Setup(org.openjdk.jmh.annotations.Setup)

Example 5 with HyperUniquesSerde

use of org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde in project druid by druid-io.

the class IndexMergeBenchmark method setup.

@Setup
public void setup() throws IOException {
    log.info("SETUP CALLED AT " + System.currentTimeMillis());
    indexMergerV9 = new IndexMergerV9(JSON_MAPPER, INDEX_IO, getSegmentWriteOutMediumFactory(factoryType));
    ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
    indexesToMerge = new ArrayList<>();
    schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);
    for (int i = 0; i < numSegments; i++) {
        DataGenerator gen = new DataGenerator(schemaInfo.getColumnSchemas(), RNG_SEED + i, schemaInfo.getDataInterval(), rowsPerSegment);
        IncrementalIndex incIndex = makeIncIndex();
        gen.addToIndex(incIndex, rowsPerSegment);
        tmpDir = FileUtils.createTempDir();
        log.info("Using temp dir: " + tmpDir.getAbsolutePath());
        File indexFile = indexMergerV9.persist(incIndex, tmpDir, new IndexSpec(), null);
        QueryableIndex qIndex = INDEX_IO.loadIndex(indexFile);
        indexesToMerge.add(qIndex);
    }
}
Also used : IndexSpec(org.apache.druid.segment.IndexSpec) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(org.apache.druid.segment.incremental.OnheapIncrementalIndex) QueryableIndex(org.apache.druid.segment.QueryableIndex) IndexMergerV9(org.apache.druid.segment.IndexMergerV9) DataGenerator(org.apache.druid.segment.generator.DataGenerator) HyperUniquesSerde(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde) File(java.io.File) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

HyperUniquesSerde (org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde)19 DataGenerator (org.apache.druid.segment.generator.DataGenerator)14 Setup (org.openjdk.jmh.annotations.Setup)14 InputRow (org.apache.druid.data.input.InputRow)6 IndexSpec (org.apache.druid.segment.IndexSpec)6 File (java.io.File)5 StupidPool (org.apache.druid.collections.StupidPool)4 OffheapBufferGenerator (org.apache.druid.offheap.OffheapBufferGenerator)4 QueryableIndex (org.apache.druid.segment.QueryableIndex)4 IncrementalIndex (org.apache.druid.segment.incremental.IncrementalIndex)4 OnheapIncrementalIndex (org.apache.druid.segment.incremental.OnheapIncrementalIndex)4 ArrayList (java.util.ArrayList)3 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)2 ByteBuffer (java.nio.ByteBuffer)2 DefaultBlockingPool (org.apache.druid.collections.DefaultBlockingPool)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 DruidProcessingConfig (org.apache.druid.query.DruidProcessingConfig)2 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2