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;
}
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);
}
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);
}
}
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);
}
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);
}
}
Aggregations