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