Search in sources :

Example 26 with ColumnValueSelector

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

the class ExpressionVirtualColumnTest method testLongSelectorOfTimeColumn.

@Test
public void testLongSelectorOfTimeColumn() {
    final ColumnValueSelector selector = TIME_FLOOR.makeColumnValueSelector("expr", COLUMN_SELECTOR_FACTORY);
    CURRENT_ROW.set(ROW0);
    Assert.assertEquals(DateTimes.of("2000-01-01").getMillis(), selector.getLong());
    Assert.assertEquals((float) DateTimes.of("2000-01-01").getMillis(), selector.getFloat(), 0.0f);
    Assert.assertEquals((double) DateTimes.of("2000-01-01").getMillis(), selector.getDouble(), 0.0d);
    Assert.assertEquals(DateTimes.of("2000-01-01").getMillis(), selector.getObject());
    CURRENT_ROW.set(ROW1);
    Assert.assertEquals(DateTimes.of("2000-01-01").getMillis(), selector.getLong());
    CURRENT_ROW.set(ROW2);
    Assert.assertEquals(DateTimes.of("2000-01-01").getMillis(), selector.getLong());
    CURRENT_ROW.set(ROW3);
    Assert.assertEquals(DateTimes.of("2000-01-02").getMillis(), selector.getLong());
    Assert.assertEquals(DateTimes.of("2000-01-02").getMillis(), selector.getDouble(), 0.0);
}
Also used : ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 27 with ColumnValueSelector

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

the class ExpressionVirtualColumnTest method testLongSelectorWithZLikeExprMacro.

@Test
public void testLongSelectorWithZLikeExprMacro() {
    final ColumnValueSelector selector = Z_LIKE.makeColumnValueSelector("expr", COLUMN_SELECTOR_FACTORY);
    CURRENT_ROW.set(ROW0);
    Assert.assertEquals(0L, selector.getLong());
    CURRENT_ROW.set(ROW1);
    Assert.assertEquals(0L, selector.getLong());
    CURRENT_ROW.set(ROW2);
    Assert.assertEquals(1L, selector.getLong());
    CURRENT_ROW.set(ROW3);
    Assert.assertEquals(1L, selector.getLong());
}
Also used : ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 28 with ColumnValueSelector

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

the class ArrayDoubleGroupByColumnSelectorStrategyTest method testAddingInDictionaryWithObjects.

@Test
public void testAddingInDictionaryWithObjects() {
    ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
    Mockito.when(columnValueSelector.getObject()).thenReturn(new Object[] { 4.0D, 2.0D });
    Assert.assertEquals(3, strategy.getOnlyValue(columnValueSelector));
    GroupByColumnSelectorPlus groupByColumnSelectorPlus = Mockito.mock(GroupByColumnSelectorPlus.class);
    Mockito.when(groupByColumnSelectorPlus.getResultRowPosition()).thenReturn(0);
    ResultRow row = ResultRow.create(1);
    buffer1.putInt(3);
    strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0);
    Assert.assertEquals(new ComparableList(ImmutableList.of(4.0, 2.0)), row.get(0));
}
Also used : ResultRow(org.apache.druid.query.groupby.ResultRow) ComparableList(org.apache.druid.segment.data.ComparableList) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) Test(org.junit.Test)

Example 29 with ColumnValueSelector

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

the class ArrayDoubleGroupByColumnSelectorStrategyTest method testSanity.

@Test
public void testSanity() {
    ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
    Mockito.when(columnValueSelector.getObject()).thenReturn(ImmutableList.of(1.0, 2.0));
    Assert.assertEquals(0, strategy.getOnlyValue(columnValueSelector));
    GroupByColumnSelectorPlus groupByColumnSelectorPlus = Mockito.mock(GroupByColumnSelectorPlus.class);
    Mockito.when(groupByColumnSelectorPlus.getResultRowPosition()).thenReturn(0);
    ResultRow row = ResultRow.create(1);
    buffer1.putInt(0);
    strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0);
    Assert.assertEquals(new ComparableList(ImmutableList.of(1.0, 2.0)), row.get(0));
}
Also used : ResultRow(org.apache.druid.query.groupby.ResultRow) ComparableList(org.apache.druid.segment.data.ComparableList) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) Test(org.junit.Test)

Example 30 with ColumnValueSelector

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

the class ArrayStringGroupByColumnSelectorStrategyTest method testAddingInDictionary.

@Test
public void testAddingInDictionary() {
    ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
    Mockito.when(columnValueSelector.getObject()).thenReturn(ImmutableList.of("f", "a"));
    Assert.assertEquals(3, strategy.getOnlyValue(columnValueSelector));
    GroupByColumnSelectorPlus groupByColumnSelectorPlus = Mockito.mock(GroupByColumnSelectorPlus.class);
    Mockito.when(groupByColumnSelectorPlus.getResultRowPosition()).thenReturn(0);
    ResultRow row = ResultRow.create(1);
    buffer1.putInt(3);
    strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0);
    Assert.assertEquals(ComparableStringArray.of("f", "a"), row.get(0));
}
Also used : ResultRow(org.apache.druid.query.groupby.ResultRow) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) Test(org.junit.Test)

Aggregations

ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)32 Test (org.junit.Test)18 Cursor (org.apache.druid.segment.Cursor)13 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)12 ImmutableList (com.google.common.collect.ImmutableList)9 TestExprMacroTable (org.apache.druid.query.expression.TestExprMacroTable)9 ResultRow (org.apache.druid.query.groupby.ResultRow)9 VirtualColumns (org.apache.druid.segment.VirtualColumns)9 List (java.util.List)8 NullHandling (org.apache.druid.common.config.NullHandling)8 Granularities (org.apache.druid.java.util.common.granularity.Granularities)8 Sequence (org.apache.druid.java.util.common.guava.Sequence)8 Closer (org.apache.druid.java.util.common.io.Closer)8 QueryableIndex (org.apache.druid.segment.QueryableIndex)8 GeneratorSchemaInfo (org.apache.druid.segment.generator.GeneratorSchemaInfo)8 SegmentGenerator (org.apache.druid.segment.generator.SegmentGenerator)8 DataSegment (org.apache.druid.timeline.DataSegment)8 LinearShardSpec (org.apache.druid.timeline.partition.LinearShardSpec)8 TimeUnit (java.util.concurrent.TimeUnit)7 Expr (org.apache.druid.math.expr.Expr)7