Search in sources :

Example 6 with UpdateDoublesSketch

use of org.apache.datasketches.quantiles.UpdateDoublesSketch in project druid by druid-io.

the class GenerateTestData method main.

public static void main(String[] args) throws Exception {
    Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv");
    Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv");
    BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8);
    BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8);
    Random rand = ThreadLocalRandom.current();
    int sequenceNumber = 0;
    for (int i = 0; i < 20; i++) {
        int product = rand.nextInt(10);
        UpdateDoublesSketch sketch = DoublesSketch.builder().build();
        for (int j = 0; j < 20; j++) {
            double value = rand.nextDouble();
            buildData.write("2016010101");
            buildData.write('\t');
            // dimension with unique numbers for ingesting raw data
            buildData.write(Integer.toString(sequenceNumber));
            buildData.write('\t');
            // product dimension
            buildData.write(Integer.toString(product));
            buildData.write('\t');
            buildData.write(Double.toString(value));
            buildData.newLine();
            sketch.update(value);
            sequenceNumber++;
        }
        sketchData.write("2016010101");
        sketchData.write('\t');
        // product dimension
        sketchData.write(Integer.toString(product));
        sketchData.write('\t');
        sketchData.write(StringUtils.encodeBase64String(sketch.toByteArray(true)));
        sketchData.newLine();
    }
    buildData.close();
    sketchData.close();
}
Also used : Path(java.nio.file.Path) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) UpdateDoublesSketch(org.apache.datasketches.quantiles.UpdateDoublesSketch) BufferedWriter(java.io.BufferedWriter)

Aggregations

UpdateDoublesSketch (org.apache.datasketches.quantiles.UpdateDoublesSketch)6 WritableMemory (org.apache.datasketches.memory.WritableMemory)2 BufferedWriter (java.io.BufferedWriter)1 Path (java.nio.file.Path)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 ArrayOfDoublesSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)1 ArrayOfDoublesSketchIterator (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator)1