Search in sources :

Example 1 with SerializerUtils

use of io.druid.common.utils.SerializerUtils in project druid by druid-io.

the class StringDimensionMergerLegacy method writeValueMetadataToFile.

@Override
public void writeValueMetadataToFile(final FileOutputSupplier valueEncodingFile) throws IOException {
    final SerializerUtils serializerUtils = new SerializerUtils();
    dictionaryWriter.close();
    serializerUtils.writeString(valueEncodingFile, dimensionName);
    ByteStreams.copy(dictionaryWriter.combineStreams(), valueEncodingFile);
    // save this File reference, we will read from it later when building bitmap/spatial indexes
    dictionaryFile = valueEncodingFile.getFile();
}
Also used : SerializerUtils(io.druid.common.utils.SerializerUtils)

Example 2 with SerializerUtils

use of io.druid.common.utils.SerializerUtils in project druid by druid-io.

the class StringDimensionMergerLegacy method writeIndexesToFiles.

@Override
public void writeIndexesToFiles(final ByteSink invertedIndexFile, final OutputSupplier<FileOutputStream> spatialIndexFile) throws IOException {
    final SerializerUtils serializerUtils = new SerializerUtils();
    final OutputSupplier<OutputStream> invertedIndexOutputSupplier = new OutputSupplier<OutputStream>() {

        @Override
        public OutputStream getOutput() throws IOException {
            return invertedIndexFile.openStream();
        }
    };
    bitmapWriter.close();
    serializerUtils.writeString(invertedIndexOutputSupplier, dimensionName);
    ByteStreams.copy(bitmapWriter.combineStreams(), invertedIndexOutputSupplier);
    if (capabilities.hasSpatialIndexes()) {
        spatialWriter.close();
        serializerUtils.writeString(spatialIndexFile, dimensionName);
        ByteStreams.copy(spatialWriter.combineStreams(), spatialIndexFile);
    }
}
Also used : FileOutputSupplier(io.druid.common.guava.FileOutputSupplier) OutputSupplier(com.google.common.io.OutputSupplier) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SerializerUtils(io.druid.common.utils.SerializerUtils)

Example 3 with SerializerUtils

use of io.druid.common.utils.SerializerUtils in project druid by druid-io.

the class StringDimensionMergerLegacy method writeIndexes.

@Override
public void writeIndexes(List<IntBuffer> segmentRowNumConversions, Closer closer) throws IOException {
    final SerializerUtils serializerUtils = new SerializerUtils();
    long dimStartTime = System.currentTimeMillis();
    final BitmapSerdeFactory bitmapSerdeFactory = indexSpec.getBitmapSerdeFactory();
    String bmpFilename = String.format("%s.inverted", dimensionName);
    bitmapWriter = new GenericIndexedWriter<>(ioPeon, bmpFilename, bitmapSerdeFactory.getObjectStrategy());
    bitmapWriter.open();
    final MappedByteBuffer dimValsMapped = Files.map(dictionaryFile);
    closer.register(new Closeable() {

        @Override
        public void close() throws IOException {
            ByteBufferUtils.unmap(dimValsMapped);
        }
    });
    if (!dimensionName.equals(serializerUtils.readString(dimValsMapped))) {
        throw new ISE("dimensions[%s] didn't equate!?  This is a major WTF moment.", dimensionName);
    }
    Indexed<String> dimVals = GenericIndexed.read(dimValsMapped, GenericIndexed.STRING_STRATEGY);
    log.info("Starting dimension[%s] with cardinality[%,d]", dimensionName, dimVals.size());
    final BitmapFactory bmpFactory = bitmapSerdeFactory.getBitmapFactory();
    RTree tree = null;
    spatialWriter = null;
    boolean hasSpatial = capabilities.hasSpatialIndexes();
    if (hasSpatial) {
        String spatialFilename = String.format("%s.spatial", dimensionName);
        spatialWriter = new ByteBufferWriter<>(ioPeon, spatialFilename, new IndexedRTree.ImmutableRTreeObjectStrategy(bmpFactory));
        spatialWriter.open();
        tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bmpFactory), bmpFactory);
    }
    IndexSeeker[] dictIdSeeker = toIndexSeekers(adapters, dimConversions, dimensionName);
    //Iterate all dim values's dictionary id in ascending order which in line with dim values's compare result.
    for (int dictId = 0; dictId < dimVals.size(); dictId++) {
        progress.progress();
        mergeBitmaps(segmentRowNumConversions, dimVals, bmpFactory, tree, hasSpatial, dictIdSeeker, dictId, adapters, dimensionName, nullRowsBitmap, bitmapWriter);
    }
    log.info("Completed dimension[%s] in %,d millis.", dimensionName, System.currentTimeMillis() - dimStartTime);
    if (hasSpatial) {
        spatialWriter.write(ImmutableRTree.newImmutableFromMutable(tree));
    }
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) LinearGutmanSplitStrategy(io.druid.collections.spatial.split.LinearGutmanSplitStrategy) MappedByteBuffer(java.nio.MappedByteBuffer) ISE(io.druid.java.util.common.ISE) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) ImmutableRTree(io.druid.collections.spatial.ImmutableRTree) IndexedRTree(io.druid.segment.data.IndexedRTree) RTree(io.druid.collections.spatial.RTree) BitmapSerdeFactory(io.druid.segment.data.BitmapSerdeFactory) SerializerUtils(io.druid.common.utils.SerializerUtils)

Aggregations

SerializerUtils (io.druid.common.utils.SerializerUtils)3 OutputSupplier (com.google.common.io.OutputSupplier)1 BitmapFactory (io.druid.collections.bitmap.BitmapFactory)1 ImmutableRTree (io.druid.collections.spatial.ImmutableRTree)1 RTree (io.druid.collections.spatial.RTree)1 LinearGutmanSplitStrategy (io.druid.collections.spatial.split.LinearGutmanSplitStrategy)1 FileOutputSupplier (io.druid.common.guava.FileOutputSupplier)1 ISE (io.druid.java.util.common.ISE)1 BitmapSerdeFactory (io.druid.segment.data.BitmapSerdeFactory)1 IndexedRTree (io.druid.segment.data.IndexedRTree)1 Closeable (java.io.Closeable)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 MappedByteBuffer (java.nio.MappedByteBuffer)1