Search in sources :

Example 1 with FixedBitSingleValueReader

use of com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader in project pinot by linkedin.

the class ColumnIndexContainer method loadUnsorted.

private static ColumnIndexContainer loadUnsorted(String column, SegmentDirectory.Reader segmentReader, ColumnMetadata metadata, ImmutableDictionaryReader dictionary, boolean loadInverted) throws IOException {
    PinotDataBuffer fwdIndexBuffer = segmentReader.getIndexFor(column, ColumnIndexType.FORWARD_INDEX);
    SingleColumnSingleValueReader fwdIndexReader;
    if (dictionary != null) {
        fwdIndexReader = new FixedBitSingleValueReader(fwdIndexBuffer, metadata.getTotalDocs(), metadata.getBitsPerElement(), metadata.hasNulls());
    } else {
        // TODO: Replace hard-coded compressor with getting information from meta-data.
        fwdIndexReader = getRawIndexReader(fwdIndexBuffer, metadata.getDataType());
    }
    BitmapInvertedIndexReader invertedIndex = null;
    if (loadInverted) {
        PinotDataBuffer invertedIndexBuffer = segmentReader.getIndexFor(column, ColumnIndexType.INVERTED_INDEX);
        invertedIndex = new BitmapInvertedIndexReader(invertedIndexBuffer, metadata.getCardinality());
    }
    return new UnsortedSVColumnIndexContainer(column, metadata, fwdIndexReader, dictionary, invertedIndex);
}
Also used : SingleColumnSingleValueReader(com.linkedin.pinot.core.io.reader.SingleColumnSingleValueReader) PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedBitSingleValueReader(com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader) BitmapInvertedIndexReader(com.linkedin.pinot.core.segment.index.readers.BitmapInvertedIndexReader)

Example 2 with FixedBitSingleValueReader

use of com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader in project pinot by linkedin.

the class InvertedIndexHandler method createInvertedIndexForColumn.

private void createInvertedIndexForColumn(ColumnMetadata columnMetadata) throws IOException {
    String column = columnMetadata.getColumnName();
    File inProgress = new File(indexDir, column + ".inv.inprogress");
    File invertedIndexFile = new File(indexDir, column + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION);
    if (!inProgress.exists()) {
        if (segmentWriter.hasIndexFor(column, ColumnIndexType.INVERTED_INDEX)) {
            // Skip creating inverted index if already exists.
            LOGGER.info("Found inverted index for segment: {}, column: {}", segmentName, column);
            return;
        }
        // Create a marker file.
        FileUtils.touch(inProgress);
    } else {
        // Marker file exists, which means last run gets interrupted.
        // Remove inverted index if exists.
        // For v1 and v2, it's the actual inverted index. For v3, it's the temporary inverted index.
        FileUtils.deleteQuietly(invertedIndexFile);
    }
    // Create new inverted index for the column.
    LOGGER.info("Creating new inverted index for segment: {}, column: {}", segmentName, column);
    int totalDocs = columnMetadata.getTotalDocs();
    OffHeapBitmapInvertedIndexCreator creator = new OffHeapBitmapInvertedIndexCreator(indexDir, columnMetadata.getCardinality(), totalDocs, columnMetadata.getTotalNumberOfEntries(), columnMetadata.getFieldSpec());
    try (DataFileReader fwdIndex = getForwardIndexReader(columnMetadata, segmentWriter)) {
        if (columnMetadata.isSingleValue()) {
            // Single-value column.
            FixedBitSingleValueReader svFwdIndex = (FixedBitSingleValueReader) fwdIndex;
            for (int i = 0; i < totalDocs; i++) {
                creator.add(i, svFwdIndex.getInt(i));
            }
        } else {
            // Multi-value column.
            SingleColumnMultiValueReader mvFwdIndex = (SingleColumnMultiValueReader) fwdIndex;
            int[] dictIds = new int[columnMetadata.getMaxNumberOfMultiValues()];
            for (int i = 0; i < totalDocs; i++) {
                int len = mvFwdIndex.getIntArray(i, dictIds);
                creator.add(i, dictIds, len);
            }
        }
    }
    creator.seal();
    // For v3, write the generated inverted index file into the single file and remove it.
    if (segmentVersion == SegmentVersion.v3) {
        LoaderUtils.writeIndexToV3Format(segmentWriter, column, invertedIndexFile, ColumnIndexType.INVERTED_INDEX);
    }
    // Delete the marker file.
    FileUtils.deleteQuietly(inProgress);
    LOGGER.info("Created inverted index for segment: {}, column: {}", segmentName, column);
}
Also used : DataFileReader(com.linkedin.pinot.core.io.reader.DataFileReader) OffHeapBitmapInvertedIndexCreator(com.linkedin.pinot.core.segment.creator.impl.inv.OffHeapBitmapInvertedIndexCreator) FixedBitSingleValueReader(com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader) SingleColumnMultiValueReader(com.linkedin.pinot.core.io.reader.SingleColumnMultiValueReader) File(java.io.File)

Example 3 with FixedBitSingleValueReader

use of com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader in project pinot by linkedin.

the class BenchmarkFileRead method readSVs.

/*@Benchmark
  @OutputTimeUnit(TimeUnit.MILLISECONDS)
  public void test() {
    byteBuffer.rewind();
    byte[] rawData = new byte[length];

    byteBuffer.rewind();
    for (int i = 0; i < length; i++) {
      rawData[i] = byteBuffer.get();
    }
  }*/
@Benchmark
@BenchmarkMode({ Mode.SampleTime })
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void readSVs() throws IOException {
    int rows = 25000000;
    int columnSizeInBits = 3;
    boolean isMMap = true;
    boolean hasNulls = false;
    PinotDataBuffer dataBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "benchmark");
    FixedBitSingleValueReader reader = new FixedBitSingleValueReader(dataBuffer, rows, columnSizeInBits, hasNulls);
    int[] result2 = new int[rows];
    for (int i = 0; i < rows; i++) {
        result2[i] = reader.getInt(i);
    }
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedBitSingleValueReader(com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 4 with FixedBitSingleValueReader

use of com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader in project pinot by linkedin.

the class FixedBitSingleValueTest method testV2.

@Test
public void testV2() throws Exception {
    int ROWS = 1000;
    for (int numBits = 1; numBits < 32; numBits++) {
        File file = new File(this.getClass().getName() + "_" + numBits + ".test");
        FixedBitSingleValueWriter writer = new FixedBitSingleValueWriter(file, ROWS, numBits);
        int[] data = new int[ROWS];
        Random random = new Random();
        int max = (int) Math.pow(2, numBits);
        for (int i = 0; i < ROWS; i++) {
            data[i] = random.nextInt(max);
            writer.setInt(i, data[i]);
        }
        writer.close();
        PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
        FixedBitSingleValueReader reader = new FixedBitSingleValueReader(heapBuffer, ROWS, numBits);
        int[] read = new int[ROWS];
        for (int i = 0; i < ROWS; i++) {
            read[i] = reader.getInt(i);
        //Assert.assertEquals(reader.getInt(i), data[i],
        //  "Failed for bit:" + numBits + " Expected " + data[i] + " but found " + reader.getInt(i) + "  at " + i);
        }
        LOGGER.trace(Arrays.toString(data));
        LOGGER.trace(Arrays.toString(read));
        reader.close();
        heapBuffer.close();
        file.delete();
    }
}
Also used : Random(java.util.Random) PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) FixedBitSingleValueWriter(com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter) FixedBitSingleValueReader(com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

FixedBitSingleValueReader (com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader)3 PinotDataBuffer (com.linkedin.pinot.core.segment.memory.PinotDataBuffer)3 File (java.io.File)2 DataFileReader (com.linkedin.pinot.core.io.reader.DataFileReader)1 SingleColumnMultiValueReader (com.linkedin.pinot.core.io.reader.SingleColumnMultiValueReader)1 SingleColumnSingleValueReader (com.linkedin.pinot.core.io.reader.SingleColumnSingleValueReader)1 FixedBitSingleValueReader (com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader)1 FixedBitSingleValueWriter (com.linkedin.pinot.core.io.writer.impl.v2.FixedBitSingleValueWriter)1 OffHeapBitmapInvertedIndexCreator (com.linkedin.pinot.core.segment.creator.impl.inv.OffHeapBitmapInvertedIndexCreator)1 BitmapInvertedIndexReader (com.linkedin.pinot.core.segment.index.readers.BitmapInvertedIndexReader)1 Random (java.util.Random)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)1 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)1 Test (org.testng.annotations.Test)1