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