Search in sources :

Example 6 with ComparableList

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

the class GroupByQueryRunnerTest method testNestedGroupByWithLongArrays.

@Test
public void testNestedGroupByWithLongArrays() {
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING");
    }
    cannotVectorize();
    GroupByQuery inner = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setVirtualColumns(new ExpressionVirtualColumn("v0", "array(1,2)", ColumnType.LONG_ARRAY, ExprMacroTable.nil())).setDimensions(new DefaultDimensionSpec("v0", "alias", ColumnType.LONG_ARRAY)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
    GroupByQuery outer = makeQueryBuilder().setDataSource(new QueryDataSource(inner)).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("alias", "alias_outer", ColumnType.LONG_ARRAY)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
    List<ResultRow> expectedResults = ImmutableList.of(makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1L, 2L)), "rows", 1L));
    Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outer);
    TestHelper.assertExpectedObjects(expectedResults, results, "long-nested-groupby-arrays");
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) QueryDataSource(org.apache.druid.query.QueryDataSource) ComparableList(org.apache.druid.segment.data.ComparableList) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 7 with ComparableList

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

the class ArrayDoubleGroupByColumnSelectorStrategyTest method testAddingInDictionary.

@Test
public void testAddingInDictionary() {
    ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
    Mockito.when(columnValueSelector.getObject()).thenReturn(ImmutableList.of(4.0, 2.0));
    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 8 with ComparableList

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

the class ClientQuerySegmentWalkerTest method testGroupByOnArraysDoublesAsString.

@Test
public void testGroupByOnArraysDoublesAsString() {
    final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("ad")).build().withId(DUMMY_QUERY_ID);
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { new ComparableList(ImmutableList.of(1.0, 2.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(2.0, 4.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(3.0, 6.0)).toString() }, new Object[] { new ComparableList(ImmutableList.of(4.0, 8.0)).toString() }));
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) ComparableList(org.apache.druid.segment.data.ComparableList) Test(org.junit.Test)

Example 9 with ComparableList

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

the class ClientQuerySegmentWalkerTest method testGroupByOnArraysLongs.

@Test
public void testGroupByOnArraysLongs() {
    final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(new DefaultDimensionSpec("al", "al", ColumnType.LONG_ARRAY)).build().withId(DUMMY_QUERY_ID);
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { new ComparableList(ImmutableList.of(1L, 2L)) }, new Object[] { new ComparableList(ImmutableList.of(2L, 4L)) }, new Object[] { new ComparableList(ImmutableList.of(3L, 6L)) }, new Object[] { new ComparableList(ImmutableList.of(4L, 8L)) }));
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) ComparableList(org.apache.druid.segment.data.ComparableList) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 10 with ComparableList

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

the class ClientQuerySegmentWalkerTest method testGroupByOnArraysDoubles.

@Test
public void testGroupByOnArraysDoubles() {
    final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(new DefaultDimensionSpec("ad", "ad", ColumnType.DOUBLE_ARRAY)).build().withId(DUMMY_QUERY_ID);
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { new ComparableList(ImmutableList.of(1.0, 2.0)) }, new Object[] { new ComparableList(ImmutableList.of(2.0, 4.0)) }, new Object[] { new ComparableList(ImmutableList.of(3.0, 6.0)) }, new Object[] { new ComparableList(ImmutableList.of(4.0, 8.0)) }));
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) ComparableList(org.apache.druid.segment.data.ComparableList) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

ComparableList (org.apache.druid.segment.data.ComparableList)15 Test (org.junit.Test)13 ResultRow (org.apache.druid.query.groupby.ResultRow)6 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)5 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)4 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)3 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)3 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)2 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)2 QueryDataSource (org.apache.druid.query.QueryDataSource)1 StringComparator (org.apache.druid.query.ordering.StringComparator)1 ColumnType (org.apache.druid.segment.column.ColumnType)1 ComparableStringArray (org.apache.druid.segment.data.ComparableStringArray)1