Search in sources :

Example 16 with VirtualColumns

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

the class VirtualColumnsTest method testExists.

@Test
public void testExists() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    Assert.assertTrue(virtualColumns.exists("expr"));
    Assert.assertTrue(virtualColumns.exists("foo"));
    Assert.assertTrue(virtualColumns.exists("foo.5"));
    Assert.assertFalse(virtualColumns.exists("bar"));
}
Also used : VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 17 with VirtualColumns

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

the class VirtualColumnsTest method testGetColumnCapabilitiesDoubleBase.

@Test
public void testGetColumnCapabilitiesDoubleBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> {
        if (REAL_COLUMN_NAME.equals(column)) {
            return ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE);
        } else {
            return null;
        }
    };
    Assert.assertEquals(ValueType.FLOAT, virtualColumns.getColumnCapabilities(baseInspector, "expr").getType());
    Assert.assertEquals(ValueType.DOUBLE, 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 18 with VirtualColumns

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

the class VirtualColumnsTest method testMakeSelectorsWithDotSupportBaseNameOnly.

@Test
public void testMakeSelectorsWithDotSupportBaseNameOnly() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final BaseObjectColumnValueSelector objectSelector = virtualColumns.makeColumnValueSelector("foo", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo", "x"), null);
    final BaseFloatColumnValueSelector floatSelector = virtualColumns.makeColumnValueSelector("foo", null);
    final BaseLongColumnValueSelector longSelector = virtualColumns.makeColumnValueSelector("foo", null);
    Assert.assertEquals(-1L, objectSelector.getObject());
    Assert.assertEquals("-1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals(-1.0f, floatSelector.getFloat(), 0.0f);
    Assert.assertEquals(-1L, 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)

Example 19 with VirtualColumns

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

the class VirtualColumnsTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    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.assertEquals(virtualColumns, virtualColumns);
    Assert.assertEquals(virtualColumns, virtualColumns2);
    Assert.assertNotEquals(VirtualColumns.EMPTY, virtualColumns);
    Assert.assertNotEquals(VirtualColumns.EMPTY, null);
    Assert.assertEquals(virtualColumns.hashCode(), virtualColumns.hashCode());
    Assert.assertEquals(virtualColumns.hashCode(), virtualColumns2.hashCode());
    Assert.assertNotEquals(VirtualColumns.EMPTY.hashCode(), virtualColumns.hashCode());
}
Also used : VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 20 with VirtualColumns

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

the class VirtualColumnsTest method testWrapInspectorDoubleBase.

@Test
public void testWrapInspectorDoubleBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> {
        if (REAL_COLUMN_NAME.equals(column)) {
            return ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE);
        } else {
            return null;
        }
    };
    final ColumnInspector wrappedInspector = virtualColumns.wrapInspector(baseInspector);
    Assert.assertEquals(ValueType.FLOAT, wrappedInspector.getColumnCapabilities("expr").getType());
    Assert.assertEquals(ValueType.DOUBLE, wrappedInspector.getColumnCapabilities("expr2").getType());
    Assert.assertEquals(ValueType.DOUBLE, wrappedInspector.getColumnCapabilities(REAL_COLUMN_NAME).getType());
}
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)

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