Search in sources :

Example 1 with StarTreeInterf

use of com.linkedin.pinot.core.startree.StarTreeInterf in project pinot by linkedin.

the class SegmentDumpTool method doMain.

public void doMain(String[] args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);
    parser.parseArgument(args);
    File segmentDir = new File(segmentPath);
    SegmentMetadata metadata = new SegmentMetadataImpl(segmentDir);
    // All columns by default
    if (columnNames == null) {
        columnNames = new ArrayList<String>(metadata.getSchema().getColumnNames());
        Collections.sort(columnNames);
    }
    IndexSegment indexSegment = Loaders.IndexSegment.load(segmentDir, ReadMode.mmap);
    Map<String, Dictionary> dictionaries = new HashMap<String, Dictionary>();
    Map<String, BlockSingleValIterator> iterators = new HashMap<String, BlockSingleValIterator>();
    for (String columnName : columnNames) {
        DataSource dataSource = indexSegment.getDataSource(columnName);
        dataSource.open();
        Block block = dataSource.nextBlock();
        BlockValSet blockValSet = block.getBlockValueSet();
        BlockSingleValIterator itr = (BlockSingleValIterator) blockValSet.iterator();
        iterators.put(columnName, itr);
        dictionaries.put(columnName, dataSource.getDictionary());
    }
    System.out.print("Doc\t");
    for (String columnName : columnNames) {
        System.out.print(columnName);
        System.out.print("\t");
    }
    System.out.println();
    for (int i = 0; i < indexSegment.getSegmentMetadata().getTotalDocs(); i++) {
        System.out.print(i);
        System.out.print("\t");
        for (String columnName : columnNames) {
            FieldSpec.DataType columnType = metadata.getSchema().getFieldSpecFor(columnName).getDataType();
            BlockSingleValIterator itr = iterators.get(columnName);
            Integer encodedValue = itr.nextIntVal();
            Object value = dictionaries.get(columnName).get(encodedValue);
            System.out.print(value);
            System.out.print("\t");
        }
        System.out.println();
    }
    if (dumpStarTree) {
        System.out.println();
        File starTreeFile = new File(segmentDir, V1Constants.STAR_TREE_INDEX_FILE);
        StarTreeInterf tree = StarTreeSerDe.fromFile(starTreeFile, ReadMode.mmap);
        tree.printTree();
    }
}
Also used : Dictionary(com.linkedin.pinot.core.segment.index.readers.Dictionary) CmdLineParser(org.kohsuke.args4j.CmdLineParser) HashMap(java.util.HashMap) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataSource(com.linkedin.pinot.core.common.DataSource) SegmentMetadata(com.linkedin.pinot.common.segment.SegmentMetadata) BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) Block(com.linkedin.pinot.core.common.Block) BlockValSet(com.linkedin.pinot.core.common.BlockValSet) StarTreeInterf(com.linkedin.pinot.core.startree.StarTreeInterf) SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) File(java.io.File)

Example 2 with StarTreeInterf

use of com.linkedin.pinot.core.startree.StarTreeInterf in project pinot by linkedin.

the class StarTreeOnHeapToOffHeapConverter method execute.

@Override
public boolean execute() throws Exception {
    File indexDir = new File(_segmentDir);
    long start = System.currentTimeMillis();
    LOGGER.info("Loading segment {}", indexDir.getName());
    IndexSegment segment = Loaders.IndexSegment.load(indexDir, ReadMode.heap);
    long end = System.currentTimeMillis();
    LOGGER.info("Loaded segment {} in {} ms ", indexDir.getName(), (end - start));
    start = end;
    StarTreeInterf starTreeOnHeap = segment.getStarTree();
    File starTreeOffHeapFile = new File(TMP_DIR, (V1Constants.STAR_TREE_INDEX_FILE + System.currentTimeMillis()));
    // Convert the star tree on-heap to off-heap format.
    StarTreeSerDe.writeTreeOffHeapFormat(starTreeOnHeap, starTreeOffHeapFile);
    // Copy all the indexes into output directory.
    File outputDir = new File(_outputDir);
    FileUtils.deleteQuietly(outputDir);
    FileUtils.copyDirectory(indexDir, outputDir);
    // Delete the existing star tree on-heap file from the output directory.
    FileUtils.deleteQuietly(new File(_outputDir, V1Constants.STAR_TREE_INDEX_FILE));
    // Move the temp star tree off-heap file into the output directory.
    FileUtils.moveFile(starTreeOffHeapFile, new File(_outputDir, V1Constants.STAR_TREE_INDEX_FILE));
    end = System.currentTimeMillis();
    LOGGER.info("Converted segment: {} ms", (end - start));
    return true;
}
Also used : IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) StarTreeInterf(com.linkedin.pinot.core.startree.StarTreeInterf) File(java.io.File)

Aggregations

IndexSegment (com.linkedin.pinot.core.indexsegment.IndexSegment)2 StarTreeInterf (com.linkedin.pinot.core.startree.StarTreeInterf)2 File (java.io.File)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)1 SegmentMetadata (com.linkedin.pinot.common.segment.SegmentMetadata)1 Block (com.linkedin.pinot.core.common.Block)1 BlockSingleValIterator (com.linkedin.pinot.core.common.BlockSingleValIterator)1 BlockValSet (com.linkedin.pinot.core.common.BlockValSet)1 DataSource (com.linkedin.pinot.core.common.DataSource)1 SegmentMetadataImpl (com.linkedin.pinot.core.segment.index.SegmentMetadataImpl)1 Dictionary (com.linkedin.pinot.core.segment.index.readers.Dictionary)1 HashMap (java.util.HashMap)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1