Search in sources :

Example 1 with VirtualColumns

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

the class VirtualColumnsTest method testMakeSelectors.

@Test
public void testMakeSelectors() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("expr", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("expr", "x"), null);
    final DimensionSelector extractionDimensionSelector = virtualColumns.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.5)), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("expr", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("expr", null);
    Assert.assertEquals(1L, objectSelector.get());
    Assert.assertEquals("1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals("0.5", extractionDimensionSelector.lookupName(extractionDimensionSelector.getRow().get(0)));
    Assert.assertEquals(1.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(1L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 2 with VirtualColumns

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

the class VirtualColumnsTest method testMakeSelectorsWithDotSupport.

@Test
public void testMakeSelectorsWithDotSupport() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("foo.5", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo.5", "x"), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("foo.5", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("foo.5", null);
    Assert.assertEquals(5L, objectSelector.get());
    Assert.assertEquals("5", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals(5.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(5L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) Test(org.junit.Test)

Example 3 with VirtualColumns

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

the class VirtualColumnsTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper mapper = new DefaultObjectMapper();
    final ImmutableList<VirtualColumn> theColumns = ImmutableList.<VirtualColumn>of(new ExpressionVirtualColumn("expr", "x + y"), new ExpressionVirtualColumn("expr2", "x + z"));
    final VirtualColumns virtualColumns = VirtualColumns.create(theColumns);
    Assert.assertEquals(virtualColumns, mapper.readValue(mapper.writeValueAsString(virtualColumns), VirtualColumns.class));
    Assert.assertEquals(theColumns, mapper.readValue(mapper.writeValueAsString(virtualColumns), mapper.getTypeFactory().constructParametricType(List.class, VirtualColumn.class)));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) VirtualColumn(io.druid.segment.VirtualColumn) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VirtualColumns(io.druid.segment.VirtualColumns) Test(org.junit.Test)

Example 4 with VirtualColumns

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

the class VirtualColumnsTest method testGetCacheKey.

@Test
public void testGetCacheKey() throws Exception {
    final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.<VirtualColumn>of(new ExpressionVirtualColumn("expr", "x + y")));
    final VirtualColumns virtualColumns2 = VirtualColumns.create(ImmutableList.<VirtualColumn>of(new ExpressionVirtualColumn("expr", "x + y")));
    Assert.assertArrayEquals(virtualColumns.getCacheKey(), virtualColumns2.getCacheKey());
    Assert.assertFalse(Arrays.equals(virtualColumns.getCacheKey(), VirtualColumns.EMPTY.getCacheKey()));
}
Also used : VirtualColumns(io.druid.segment.VirtualColumns) Test(org.junit.Test)

Example 5 with VirtualColumns

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

the class VirtualColumnsTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() throws Exception {
    final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.<VirtualColumn>of(new ExpressionVirtualColumn("expr", "x + y")));
    final VirtualColumns virtualColumns2 = VirtualColumns.create(ImmutableList.<VirtualColumn>of(new ExpressionVirtualColumn("expr", "x + y")));
    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(io.druid.segment.VirtualColumns) Test(org.junit.Test)

Aggregations

VirtualColumns (io.druid.segment.VirtualColumns)6 Test (org.junit.Test)6 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)3 DimensionSelector (io.druid.segment.DimensionSelector)3 FloatColumnSelector (io.druid.segment.FloatColumnSelector)3 LongColumnSelector (io.druid.segment.LongColumnSelector)3 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)3 TestFloatColumnSelector (io.druid.segment.TestFloatColumnSelector)3 TestLongColumnSelector (io.druid.segment.TestLongColumnSelector)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)1 BucketExtractionFn (io.druid.query.extraction.BucketExtractionFn)1 VirtualColumn (io.druid.segment.VirtualColumn)1