Search in sources :

Example 91 with ColumnCapabilities

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

the class ExpressionVirtualColumn method capabilities.

@Override
public ColumnCapabilities capabilities(ColumnInspector inspector, String columnName) {
    final ExpressionPlan plan = ExpressionPlanner.plan(inspector, parsedExpression.get());
    final ColumnCapabilities inferred = plan.inferColumnCapabilities(outputType);
    // if we can infer the column capabilities from the expression plan, then use that
    if (inferred != null) {
        // explicit outputType is used as a hint, how did it compare to the planners inferred output type?
        if (outputType != null && inferred.getType() != outputType.getType()) {
            // but mismatches involving strings and arrays might be worth knowing about so warn
            if (!inferred.isNumeric() && !outputType.isNumeric()) {
                log.warn("Projected output type %s of expression %s does not match provided type %s", inferred.asTypeString(), expression, outputType);
            } else {
                log.debug("Projected output type %s of expression %s does not match provided type %s", inferred.asTypeString(), expression, outputType);
            }
        }
        return inferred;
    }
    // fallback to default capabilities
    return capabilities(columnName);
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 92 with ColumnCapabilities

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

the class QueryableIndexColumnCapabilitiesTest method testStringColumnWithNulls.

@Test
public void testStringColumnWithNulls() {
    ColumnCapabilities caps = INC_INDEX_WITH_NULLS.getColumnCapabilities("d1");
    Assert.assertEquals(ValueType.STRING, caps.getType());
    Assert.assertTrue(caps.hasBitmapIndexes());
    Assert.assertTrue(caps.isDictionaryEncoded().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesUnique().isTrue());
    // multi-value is unknown unless explicitly set to 'true'
    Assert.assertTrue(caps.hasMultipleValues().isUnknown());
    // at index merge or query time we 'complete' the capabilities to take a snapshot of the current state,
    // coercing any 'UNKNOWN' values to false
    Assert.assertFalse(ColumnCapabilitiesImpl.snapshot(caps, IndexMergerV9.DIMENSION_CAPABILITY_MERGE_LOGIC).hasMultipleValues().isMaybeTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
    Assert.assertTrue(caps.hasNulls().isTrue());
    caps = MMAP_INDEX_WITH_NULLS.getColumnHolder("d1").getCapabilities();
    Assert.assertEquals(ValueType.STRING, caps.getType());
    Assert.assertTrue(caps.hasBitmapIndexes());
    Assert.assertTrue(caps.isDictionaryEncoded().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertFalse(caps.hasMultipleValues().isMaybeTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
    Assert.assertTrue(caps.hasNulls().isTrue());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 93 with ColumnCapabilities

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

the class QueryableIndexColumnCapabilitiesTest method testMultiStringColumnWithNulls.

@Test
public void testMultiStringColumnWithNulls() {
    ColumnCapabilities caps = INC_INDEX_WITH_NULLS.getColumnCapabilities("d2");
    Assert.assertEquals(ValueType.STRING, caps.getType());
    Assert.assertTrue(caps.hasBitmapIndexes());
    Assert.assertTrue(caps.isDictionaryEncoded().isTrue());
    Assert.assertFalse(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertTrue(caps.hasMultipleValues().isTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
    Assert.assertTrue(caps.hasNulls().isTrue());
    caps = MMAP_INDEX_WITH_NULLS.getColumnHolder("d2").getCapabilities();
    Assert.assertEquals(ValueType.STRING, caps.getType());
    Assert.assertTrue(caps.hasBitmapIndexes());
    Assert.assertTrue(caps.isDictionaryEncoded().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesSorted().isTrue());
    Assert.assertTrue(caps.areDictionaryValuesUnique().isTrue());
    Assert.assertTrue(caps.hasMultipleValues().isTrue());
    Assert.assertFalse(caps.hasSpatialIndexes());
    Assert.assertTrue(caps.hasNulls().isTrue());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 94 with ColumnCapabilities

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

the class RowBasedColumnSelectorFactoryTest method testCapabilitiesString.

@Test
public void testCapabilitiesString() {
    ColumnCapabilities caps = RowBasedColumnSelectorFactory.getColumnCapabilities(ROW_SIGNATURE, STRING_COLUMN_NAME);
    Assert.assertEquals(ValueType.STRING, caps.getType());
    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 95 with ColumnCapabilities

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

the class RowBasedColumnSelectorFactoryTest method testCapabilitiesStringArray.

@Test
public void testCapabilitiesStringArray() {
    ColumnCapabilities caps = RowBasedColumnSelectorFactory.getColumnCapabilities(ROW_SIGNATURE, STRING_ARRAY_COLUMN_NAME);
    Assert.assertEquals(ColumnType.STRING_ARRAY, 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().isFalse());
    Assert.assertFalse(caps.hasSpatialIndexes());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)170 Test (org.junit.Test)106 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)60 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)18 ArrayList (java.util.ArrayList)12 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)12 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)10 ValueType (org.apache.druid.segment.column.ValueType)9 Nullable (javax.annotation.Nullable)8 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)8 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)8 ColumnType (org.apache.druid.segment.column.ColumnType)8 RowSignature (org.apache.druid.segment.column.RowSignature)8 BaseLongVectorValueSelector (org.apache.druid.segment.vector.BaseLongVectorValueSelector)8 File (java.io.File)6 List (java.util.List)6 TreeMap (java.util.TreeMap)6 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)6 Pair (org.apache.druid.java.util.common.Pair)6