Search in sources :

Example 11 with IAE

use of io.druid.java.util.common.IAE in project druid by druid-io.

the class DimensionSelectorUtils method makePredicateMatchingSet.

public static BitSet makePredicateMatchingSet(DimensionSelector selector, Predicate<String> predicate) {
    if (!selector.nameLookupPossibleInAdvance()) {
        throw new IAE("selector.nameLookupPossibleInAdvance() should return true");
    }
    int cardinality = selector.getValueCardinality();
    BitSet valueIds = new BitSet(cardinality);
    for (int i = 0; i < cardinality; i++) {
        if (predicate.apply(selector.lookupName(i))) {
            valueIds.set(i);
        }
    }
    return valueIds;
}
Also used : BitSet(java.util.BitSet) IAE(io.druid.java.util.common.IAE)

Example 12 with IAE

use of io.druid.java.util.common.IAE in project druid by druid-io.

the class CompressedVSizeIndexedV3Supplier method fromByteBuffer.

public static CompressedVSizeIndexedV3Supplier fromByteBuffer(ByteBuffer buffer, ByteOrder order, SmooshedFileMapper fileMapper) {
    byte versionFromBuffer = buffer.get();
    if (versionFromBuffer == VERSION) {
        CompressedIntsIndexedSupplier offsetSupplier = CompressedIntsIndexedSupplier.fromByteBuffer(buffer, order, fileMapper);
        CompressedVSizeIntsIndexedSupplier valueSupplier = CompressedVSizeIntsIndexedSupplier.fromByteBuffer(buffer, order, fileMapper);
        return new CompressedVSizeIndexedV3Supplier(offsetSupplier, valueSupplier);
    }
    throw new IAE("Unknown version[%s]", versionFromBuffer);
}
Also used : CompressedIntsIndexedSupplier(io.druid.segment.data.CompressedIntsIndexedSupplier) IAE(io.druid.java.util.common.IAE) CompressedVSizeIntsIndexedSupplier(io.druid.segment.data.CompressedVSizeIntsIndexedSupplier)

Example 13 with IAE

use of io.druid.java.util.common.IAE in project druid by druid-io.

the class GenericIndexedWriter method writeToChannelVersionTwo.

private void writeToChannelVersionTwo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException {
    if (smoosher == null) {
        throw new IAE("version 2 GenericIndexedWriter requires FileSmoosher.");
    }
    int bagSizePower = bagSizePower();
    OutputStream metaOut = Channels.newOutputStream(channel);
    metaOut.write(GenericIndexed.VERSION_TWO);
    metaOut.write(objectsSorted ? 0x1 : 0x0);
    metaOut.write(Ints.toByteArray(bagSizePower));
    metaOut.write(Ints.toByteArray(Ints.checkedCast(numWritten)));
    metaOut.write(Ints.toByteArray(fileNameByteArray.length));
    metaOut.write(fileNameByteArray);
    try (RandomAccessFile headerFile = new RandomAccessFile(ioPeon.getFile(makeFilename("headerLong")), "r")) {
        Preconditions.checkNotNull(headerFile, "header file missing.");
        long previousValuePosition = 0;
        int bagSize = 1 << bagSizePower;
        int numberOfFilesRequired = GenericIndexed.getNumberOfFilesRequired(bagSize, numWritten);
        byte[] buffer = new byte[1 << 16];
        try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("values")))) {
            int counter = -1;
            for (int i = 0; i < numberOfFilesRequired; i++) {
                if (i != numberOfFilesRequired - 1) {
                    // 8 for long bytes.
                    headerFile.seek((bagSize + counter) * Longs.BYTES);
                    counter = counter + bagSize;
                } else {
                    // for remaining items.
                    headerFile.seek((numWritten - 1) * Longs.BYTES);
                }
                long valuePosition = Long.reverseBytes(headerFile.readLong());
                long numBytesToPutInFile = valuePosition - previousValuePosition;
                try (SmooshedWriter smooshChannel = smoosher.addWithSmooshedWriter(generateValueFileName(filenameBase, i), numBytesToPutInFile)) {
                    writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is);
                    previousValuePosition = valuePosition;
                }
            }
        }
        writeHeaderLong(smoosher, headerFile, bagSizePower, buffer);
    }
}
Also used : SmooshedWriter(io.druid.java.util.common.io.smoosh.SmooshedWriter) RandomAccessFile(java.io.RandomAccessFile) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) IAE(io.druid.java.util.common.IAE) FileInputStream(java.io.FileInputStream)

Example 14 with IAE

use of io.druid.java.util.common.IAE in project druid by druid-io.

the class VSizeIndexed method readFromByteBuffer.

public static VSizeIndexed readFromByteBuffer(ByteBuffer buffer) {
    byte versionFromBuffer = buffer.get();
    if (version == versionFromBuffer) {
        int numBytes = buffer.get();
        int size = buffer.getInt();
        ByteBuffer bufferToUse = buffer.asReadOnlyBuffer();
        bufferToUse.limit(bufferToUse.position() + size);
        buffer.position(bufferToUse.limit());
        return new VSizeIndexed(bufferToUse, numBytes);
    }
    throw new IAE("Unknown version[%s]", versionFromBuffer);
}
Also used : IAE(io.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 15 with IAE

use of io.druid.java.util.common.IAE in project druid by druid-io.

the class ValidateSegments method run.

@Override
public void run() {
    if (directories.size() != 2) {
        throw new IAE("Please provide two segment directories to compare");
    }
    final Injector injector = makeInjector();
    final IndexIO indexIO = injector.getInstance(IndexIO.class);
    try {
        String dir1 = directories.get(0);
        String dir2 = directories.get(1);
        indexIO.validateTwoSegments(new File(dir1), new File(dir2));
        log.info("Segments [%s] and [%s] are identical", dir1, dir2);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : IndexIO(io.druid.segment.IndexIO) Injector(com.google.inject.Injector) IAE(io.druid.java.util.common.IAE) File(java.io.File)

Aggregations

IAE (io.druid.java.util.common.IAE)50 IOException (java.io.IOException)12 ISE (io.druid.java.util.common.ISE)10 ByteBuffer (java.nio.ByteBuffer)10 Function (com.google.common.base.Function)5 DataSegment (io.druid.timeline.DataSegment)5 URI (java.net.URI)5 Interval (org.joda.time.Interval)5 File (java.io.File)4 Nullable (javax.annotation.Nullable)4 DateTime (org.joda.time.DateTime)4 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ByteSource (com.google.common.io.ByteSource)2 Injector (com.google.inject.Injector)2 Request (com.metamx.http.client.Request)2