Search in sources :

Example 1 with LongsColumn

use of org.apache.druid.segment.column.LongsColumn in project druid by druid-io.

the class ColumnarLongsEncodeDataFromSegmentBenchmark method initializeSegmentValueIntermediaryFile.

/**
 * writes column values to an intermediary text file, 1 per line, encoders read from this file as input to write
 * encoded column files.
 */
private void initializeSegmentValueIntermediaryFile() throws IOException {
    File dir = getTmpDir();
    File dataFile = new File(dir, getColumnDataFileName(segmentName, columnName));
    if (!dataFile.exists()) {
        final IndexIO indexIO = new IndexIO(new DefaultObjectMapper(), () -> 0);
        try (final QueryableIndex index = indexIO.loadIndex(new File(segmentPath))) {
            final Set<String> columnNames = new LinkedHashSet<>();
            columnNames.add(ColumnHolder.TIME_COLUMN_NAME);
            Iterables.addAll(columnNames, index.getColumnNames());
            final ColumnHolder column = index.getColumnHolder(columnName);
            final ColumnCapabilities capabilities = column.getCapabilities();
            try (Writer writer = Files.newBufferedWriter(dataFile.toPath(), StandardCharsets.UTF_8)) {
                if (!capabilities.is(ValueType.LONG)) {
                    throw new RuntimeException("Invalid column type, expected 'Long'");
                }
                LongsColumn theColumn = (LongsColumn) column.getColumn();
                for (int i = 0; i < theColumn.length(); i++) {
                    long value = theColumn.getLongSingleValueRow(i);
                    writer.write(value + "\n");
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ColumnHolder(org.apache.druid.segment.column.ColumnHolder) LongsColumn(org.apache.druid.segment.column.LongsColumn) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) IndexIO(org.apache.druid.segment.IndexIO) QueryableIndex(org.apache.druid.segment.QueryableIndex) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) Writer(java.io.Writer)

Example 2 with LongsColumn

use of org.apache.druid.segment.column.LongsColumn in project druid by druid-io.

the class NumericNullColumnSelectorTest method testLongSelectorWithNullsCanResetOffset.

@Test
public void testLongSelectorWithNullsCanResetOffset() {
    for (ImmutableBitmap bitmap : bitmaps) {
        ColumnarLongs longs = new ColumnarLongs() {

            @Override
            public int size() {
                return numRows;
            }

            @Override
            public long get(int index) {
                return ThreadLocalRandom.current().nextLong();
            }

            @Override
            public void close() {
            }
        };
        LongsColumn columnWithNulls = LongsColumn.create(longs, bitmap);
        ColumnValueSelector<?> selector = columnWithNulls.makeColumnValueSelector(offset);
        assertOffsetCanReset(selector, bitmap, offset);
        VectorValueSelector vectorSelector = columnWithNulls.makeVectorValueSelector(vectorOffset);
        assertVectorOffsetCanReset(vectorSelector, bitmap, vectorOffset);
    }
}
Also used : LongsColumn(org.apache.druid.segment.column.LongsColumn) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) Test(org.junit.Test)

Aggregations

LongsColumn (org.apache.druid.segment.column.LongsColumn)2 File (java.io.File)1 Writer (java.io.Writer)1 LinkedHashSet (java.util.LinkedHashSet)1 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 IndexIO (org.apache.druid.segment.IndexIO)1 QueryableIndex (org.apache.druid.segment.QueryableIndex)1 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)1 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)1 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)1 Test (org.junit.Test)1