Search in sources :

Example 76 with ColumnCapabilities

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

the class RowBasedColumnSelectorFactoryTest method testCapabilitiesDouble.

@Test
public void testCapabilitiesDouble() {
    ColumnCapabilities caps = RowBasedColumnSelectorFactory.getColumnCapabilities(ROW_SIGNATURE, DOUBLE_COLUMN_NAME);
    Assert.assertEquals(ValueType.DOUBLE, caps.getType());
    Assert.assertFalse(caps.hasBitmapIndexes());
    Assert.assertFalse(caps.isDictionaryEncoded().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertFalse(caps.hasMultipleValues().isMaybeTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 77 with ColumnCapabilities

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

the class RowBasedColumnSelectorFactoryTest method testCapabilitiesComplex.

@Test
public void testCapabilitiesComplex() {
    ColumnCapabilities caps = RowBasedColumnSelectorFactory.getColumnCapabilities(ROW_SIGNATURE, COMPLEX_COLUMN_NAME);
    Assert.assertEquals(SOME_COMPLEX, caps.toColumnType());
    Assert.assertFalse(caps.hasBitmapIndexes());
    Assert.assertFalse(caps.isDictionaryEncoded().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertTrue(caps.hasMultipleValues().isUnknown());
    Assert.assertFalse(caps.hasSpatialIndexes());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 78 with ColumnCapabilities

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

the class RowBasedColumnSelectorFactoryTest method testCapabilitiesTime.

@Test
public void testCapabilitiesTime() {
    // time column takes a special path
    ColumnCapabilities caps = RowBasedColumnSelectorFactory.getColumnCapabilities(ROW_SIGNATURE, ColumnHolder.TIME_COLUMN_NAME);
    Assert.assertEquals(ValueType.LONG, caps.getType());
    Assert.assertFalse(caps.hasBitmapIndexes());
    Assert.assertFalse(caps.isDictionaryEncoded().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertFalse(caps.hasMultipleValues().isMaybeTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 79 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 80 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)

Aggregations

ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)156 Test (org.junit.Test)104 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)58 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)18 ArrayList (java.util.ArrayList)8 Nullable (javax.annotation.Nullable)8 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)8 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)8 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)8 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)8 ColumnType (org.apache.druid.segment.column.ColumnType)8 RowSignature (org.apache.druid.segment.column.RowSignature)8 ValueType (org.apache.druid.segment.column.ValueType)7 List (java.util.List)6 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)6 Pair (org.apache.druid.java.util.common.Pair)6 Expr (org.apache.druid.math.expr.Expr)6 ExpressionType (org.apache.druid.math.expr.ExpressionType)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 DimensionIndexer (org.apache.druid.segment.DimensionIndexer)6