Search in sources :

Example 6 with VirtualColumns

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

the class VirtualColumnsTest method testNonExistentSelector.

@Test
public void testNonExistentSelector() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("No such virtual column[bar]");
    virtualColumns.makeColumnValueSelector("bar", null);
}
Also used : VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 7 with VirtualColumns

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

the class VirtualColumnsTest method testGetCacheKey.

@Test
public void testGetCacheKey() {
    final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.of(new ExpressionVirtualColumn("expr", "x + y", ColumnType.FLOAT, TestExprMacroTable.INSTANCE)));
    final VirtualColumns virtualColumns2 = VirtualColumns.create(ImmutableList.of(new ExpressionVirtualColumn("expr", "x + y", ColumnType.FLOAT, TestExprMacroTable.INSTANCE)));
    Assert.assertArrayEquals(virtualColumns.getCacheKey(), virtualColumns2.getCacheKey());
    Assert.assertFalse(Arrays.equals(virtualColumns.getCacheKey(), VirtualColumns.EMPTY.getCacheKey()));
}
Also used : VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with VirtualColumns

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

the class VirtualColumnsTest method testGetColumnCapabilitiesNilBase.

@Test
public void testGetColumnCapabilitiesNilBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> null;
    Assert.assertEquals(ValueType.FLOAT, virtualColumns.getColumnCapabilities(baseInspector, "expr").getType());
    Assert.assertEquals(ValueType.LONG, virtualColumns.getColumnCapabilities(baseInspector, "expr2").getType());
    Assert.assertNull(virtualColumns.getColumnCapabilities(baseInspector, REAL_COLUMN_NAME));
}
Also used : Arrays(java.util.Arrays) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ImmutableList(com.google.common.collect.ImmutableList) DimensionSelector(org.apache.druid.segment.DimensionSelector) TestLongColumnSelector(org.apache.druid.segment.TestLongColumnSelector) BucketExtractionFn(org.apache.druid.query.extraction.BucketExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) ColumnInspector(org.apache.druid.segment.ColumnInspector) Longs(com.google.common.primitives.Longs) VirtualColumns(org.apache.druid.segment.VirtualColumns) VirtualColumn(org.apache.druid.segment.VirtualColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueType(org.apache.druid.segment.column.ValueType) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) DimensionSelectorUtils(org.apache.druid.segment.DimensionSelectorUtils) ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) TestHelper(org.apache.druid.segment.TestHelper) List(java.util.List) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) Assert(org.junit.Assert) ColumnInspector(org.apache.druid.segment.ColumnInspector) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 9 with VirtualColumns

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

the class VirtualColumnsTest method testWrapInspectorNilBase.

@Test
public void testWrapInspectorNilBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> null;
    final ColumnInspector wrappedInspector = virtualColumns.wrapInspector(baseInspector);
    Assert.assertEquals(ValueType.FLOAT, wrappedInspector.getColumnCapabilities("expr").getType());
    Assert.assertEquals(ValueType.LONG, wrappedInspector.getColumnCapabilities("expr2").getType());
    Assert.assertNull(wrappedInspector.getColumnCapabilities(REAL_COLUMN_NAME));
}
Also used : Arrays(java.util.Arrays) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ImmutableList(com.google.common.collect.ImmutableList) DimensionSelector(org.apache.druid.segment.DimensionSelector) TestLongColumnSelector(org.apache.druid.segment.TestLongColumnSelector) BucketExtractionFn(org.apache.druid.query.extraction.BucketExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) ColumnInspector(org.apache.druid.segment.ColumnInspector) Longs(com.google.common.primitives.Longs) VirtualColumns(org.apache.druid.segment.VirtualColumns) VirtualColumn(org.apache.druid.segment.VirtualColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueType(org.apache.druid.segment.column.ValueType) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) DimensionSelectorUtils(org.apache.druid.segment.DimensionSelectorUtils) ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) TestHelper(org.apache.druid.segment.TestHelper) List(java.util.List) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) Assert(org.junit.Assert) ColumnInspector(org.apache.druid.segment.ColumnInspector) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 10 with VirtualColumns

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

the class VirtualColumnsTest method testMakeSelectorsWithDotSupport.

@Test
public void testMakeSelectorsWithDotSupport() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final BaseObjectColumnValueSelector objectSelector = virtualColumns.makeColumnValueSelector("foo.5", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo.5", "x"), null);
    final BaseFloatColumnValueSelector floatSelector = virtualColumns.makeColumnValueSelector("foo.5", null);
    final BaseLongColumnValueSelector longSelector = virtualColumns.makeColumnValueSelector("foo.5", null);
    Assert.assertEquals(5L, objectSelector.getObject());
    Assert.assertEquals("5", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals(5.0f, floatSelector.getFloat(), 0.0f);
    Assert.assertEquals(5L, longSelector.getLong());
}
Also used : BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DimensionSelector(org.apache.druid.segment.DimensionSelector) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

VirtualColumns (org.apache.druid.segment.VirtualColumns)22 Test (org.junit.Test)19 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)14 Nullable (javax.annotation.Nullable)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 BaseFloatColumnValueSelector (org.apache.druid.segment.BaseFloatColumnValueSelector)9 BaseLongColumnValueSelector (org.apache.druid.segment.BaseLongColumnValueSelector)9 BaseObjectColumnValueSelector (org.apache.druid.segment.BaseObjectColumnValueSelector)9 DimensionSelector (org.apache.druid.segment.DimensionSelector)9 VirtualColumn (org.apache.druid.segment.VirtualColumn)9 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Arrays (java.util.Arrays)8 TestExprMacroTable (org.apache.druid.query.expression.TestExprMacroTable)8 ColumnInspector (org.apache.druid.segment.ColumnInspector)8 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)8 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)7 BucketExtractionFn (org.apache.druid.query.extraction.BucketExtractionFn)7