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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations