Search in sources :

Example 41 with ColumnCapabilities

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

the class FixedBucketsHistogramVectorAggregatorTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    VectorValueSelector vectorValueSelector_1 = createMock(VectorValueSelector.class);
    expect(vectorValueSelector_1.getDoubleVector()).andReturn(DOUBLES).anyTimes();
    expect(vectorValueSelector_1.getNullVector()).andReturn(NULL_VECTOR).anyTimes();
    VectorValueSelector vectorValueSelector_2 = createMock(VectorValueSelector.class);
    expect(vectorValueSelector_2.getDoubleVector()).andReturn(DOUBLES).anyTimes();
    expect(vectorValueSelector_2.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector_1);
    EasyMock.replay(vectorValueSelector_2);
    ColumnCapabilities columnCapabilities = ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE);
    vectorColumnSelectorFactory = createMock(VectorColumnSelectorFactory.class);
    expect(vectorColumnSelectorFactory.getColumnCapabilities("field_1")).andReturn(columnCapabilities).anyTimes();
    expect(vectorColumnSelectorFactory.makeValueSelector("field_1")).andReturn(vectorValueSelector_1).anyTimes();
    expect(vectorColumnSelectorFactory.getColumnCapabilities("field_2")).andReturn(columnCapabilities).anyTimes();
    expect(vectorColumnSelectorFactory.makeValueSelector("field_2")).andReturn(vectorValueSelector_2).anyTimes();
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) Before(org.junit.Before)

Example 42 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities 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 43 with ColumnCapabilities

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

the class SegmentAnalyzer method analyze.

public Map<String, ColumnAnalysis> analyze(Segment segment) {
    Preconditions.checkNotNull(segment, "segment");
    // index is null for incremental-index-based segments, but storageAdapter is always available
    final QueryableIndex index = segment.asQueryableIndex();
    final StorageAdapter storageAdapter = segment.asStorageAdapter();
    // get length and column names from storageAdapter
    final int length = storageAdapter.getNumRows();
    Map<String, ColumnAnalysis> columns = new TreeMap<>();
    final RowSignature rowSignature = storageAdapter.getRowSignature();
    for (String columnName : rowSignature.getColumnNames()) {
        final ColumnCapabilities capabilities;
        if (storageAdapter instanceof IncrementalIndexStorageAdapter) {
            // See javadocs for getSnapshotColumnCapabilities for a discussion of why we need to do this.
            capabilities = ((IncrementalIndexStorageAdapter) storageAdapter).getSnapshotColumnCapabilities(columnName);
        } else {
            capabilities = storageAdapter.getColumnCapabilities(columnName);
        }
        final ColumnAnalysis analysis;
        switch(capabilities.getType()) {
            case LONG:
                final int bytesPerRow = ColumnHolder.TIME_COLUMN_NAME.equals(columnName) ? NUM_BYTES_IN_TIMESTAMP : Long.BYTES;
                analysis = analyzeNumericColumn(capabilities, length, bytesPerRow);
                break;
            case FLOAT:
                analysis = analyzeNumericColumn(capabilities, length, NUM_BYTES_IN_TEXT_FLOAT);
                break;
            case DOUBLE:
                analysis = analyzeNumericColumn(capabilities, length, Double.BYTES);
                break;
            case STRING:
                if (index != null) {
                    analysis = analyzeStringColumn(capabilities, index.getColumnHolder(columnName));
                } else {
                    analysis = analyzeStringColumn(capabilities, storageAdapter, columnName);
                }
                break;
            case COMPLEX:
                final ColumnHolder columnHolder = index != null ? index.getColumnHolder(columnName) : null;
                analysis = analyzeComplexColumn(capabilities, columnHolder);
                break;
            default:
                log.warn("Unknown column type[%s].", capabilities.asTypeString());
                analysis = ColumnAnalysis.error(StringUtils.format("unknown_type_%s", capabilities.asTypeString()));
        }
        columns.put(columnName, analysis);
    }
    return columns;
}
Also used : ColumnHolder(org.apache.druid.segment.column.ColumnHolder) QueryableIndex(org.apache.druid.segment.QueryableIndex) ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) StorageAdapter(org.apache.druid.segment.StorageAdapter) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) TreeMap(java.util.TreeMap) RowSignature(org.apache.druid.segment.column.RowSignature) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 44 with ColumnCapabilities

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

the class UseIndexesStrategy method partitionDimensionList.

/**
 * Split the given dimensions list into bitmap-supporting dimensions and non-bitmap supporting ones.
 * Note that the returned lists are free to modify.
 */
private static Pair<List<DimensionSpec>, List<DimensionSpec>> partitionDimensionList(StorageAdapter adapter, List<DimensionSpec> dimensions) {
    final List<DimensionSpec> bitmapDims = new ArrayList<>();
    final List<DimensionSpec> nonBitmapDims = new ArrayList<>();
    final List<DimensionSpec> dimsToSearch = getDimsToSearch(adapter.getAvailableDimensions(), dimensions);
    for (DimensionSpec spec : dimsToSearch) {
        ColumnCapabilities capabilities = adapter.getColumnCapabilities(spec.getDimension());
        if (capabilities == null) {
            continue;
        }
        if (capabilities.hasBitmapIndexes()) {
            bitmapDims.add(spec);
        } else {
            nonBitmapDims.add(spec);
        }
    }
    return new Pair<>(bitmapDims, nonBitmapDims);
}
Also used : DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ArrayList(java.util.ArrayList) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) Pair(org.apache.druid.java.util.common.Pair)

Example 45 with ColumnCapabilities

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

the class HashJoinSegmentStorageAdapterTest method test_getColumnCapabilities_factToCountryJoinColumn.

@Test
public void test_getColumnCapabilities_factToCountryJoinColumn() {
    final ColumnCapabilities capabilities = makeFactToCountrySegment().getColumnCapabilities(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryIsoCode");
    Assert.assertEquals(ValueType.STRING, capabilities.getType());
    Assert.assertFalse(capabilities.hasBitmapIndexes());
    Assert.assertFalse(capabilities.areDictionaryValuesUnique().isTrue());
    Assert.assertFalse(capabilities.areDictionaryValuesSorted().isTrue());
    Assert.assertTrue(capabilities.isDictionaryEncoded().isTrue());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) Test(org.junit.Test)

Aggregations

ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)78 Test (org.junit.Test)52 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)29 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)9 ArrayList (java.util.ArrayList)4 Nullable (javax.annotation.Nullable)4 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)4 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)4 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)4 QueryableIndex (org.apache.druid.segment.QueryableIndex)4 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)4 ColumnType (org.apache.druid.segment.column.ColumnType)4 RowSignature (org.apache.druid.segment.column.RowSignature)4 ValueType (org.apache.druid.segment.column.ValueType)4 List (java.util.List)3 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)3 ISE (org.apache.druid.java.util.common.ISE)3 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)3 Before (org.junit.Before)3