public static OrderByColumnSpec asc(String dimension) { return new OrderByColumnSpec(dimension, Direction.ASCENDING, null); }
public static OrderByColumnSpec desc(String dimension) { return new OrderByColumnSpec(dimension, Direction.DESCENDING, null); }
@JsonCreator public static OrderByColumnSpec fromString(String dimension) { return new OrderByColumnSpec(dimension, null, null); }
public Builder addOrderByColumn(String dimension, OrderByColumnSpec.Direction direction) { return addOrderByColumn(new OrderByColumnSpec(dimension, direction)); }
@Test public void testWithAllGranularity() { DefaultLimitSpec limitSpec = new DefaultLimitSpec( ImmutableList.of(new OrderByColumnSpec("k1", OrderByColumnSpec.Direction.ASCENDING, StringComparators.NUMERIC)), 2 ); Function<Sequence<Row>, Sequence<Row>> limitFn = limitSpec.build( ImmutableList.of(new DefaultDimensionSpec("k1", "k1", ValueType.DOUBLE)), ImmutableList.of(), ImmutableList.of(), Granularities.ALL, true ); Assert.assertEquals( ImmutableList.of(testRowsList.get(0), testRowsList.get(1)), limitFn.apply(testRowsSequence).toList() ); }
@Test public void testWithSortByDimsFirst() { DefaultLimitSpec limitSpec = new DefaultLimitSpec( ImmutableList.of(new OrderByColumnSpec("k1", OrderByColumnSpec.Direction.ASCENDING, StringComparators.NUMERIC)), 2 ); Function<Sequence<Row>, Sequence<Row>> limitFn = limitSpec.build( ImmutableList.of(new DefaultDimensionSpec("k1", "k1", ValueType.DOUBLE)), ImmutableList.of(), ImmutableList.of(), Granularities.NONE, true ); Assert.assertEquals( ImmutableList.of(testRowsList.get(2), testRowsList.get(0)), limitFn.apply(testRowsSequence).toList() ); }
@Test public void testSortDimensionDescending() { DefaultLimitSpec limitSpec = new DefaultLimitSpec( ImmutableList.of(new OrderByColumnSpec("k1", OrderByColumnSpec.Direction.DESCENDING)), 2 ); Function<Sequence<Row>, Sequence<Row>> limitFn = limitSpec.build( ImmutableList.of(new DefaultDimensionSpec("k1", "k1")), ImmutableList.of(), ImmutableList.of(), Granularities.NONE, false ); // Note: This test encodes the fact that limitSpec sorts numbers like strings; we might want to change this // in the future. Assert.assertEquals( ImmutableList.of(testRowsList.get(2), testRowsList.get(1)), limitFn.apply(testRowsSequence).toList() ); }
Collections.singletonList(new OrderByColumnSpec("rows", OrderByColumnSpec.Direction.DESCENDING)),
@Test public void testQuerySerialization() throws IOException { Query query = GroupByQuery .builder() .setDataSource(QueryRunnerTestHelper.dataSource) .setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird) .setDimensions(new DefaultDimensionSpec("quality", "alias")) .setAggregatorSpecs(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index")) .setGranularity(QueryRunnerTestHelper.dayGran) .setPostAggregatorSpecs(ImmutableList.of(new FieldAccessPostAggregator("x", "idx"))) .setLimitSpec( new DefaultLimitSpec( ImmutableList.of(new OrderByColumnSpec( "alias", OrderByColumnSpec.Direction.ASCENDING, StringComparators.LEXICOGRAPHIC )), 100 ) ) .build(); String json = jsonMapper.writeValueAsString(query); Query serdeQuery = jsonMapper.readValue(json, Query.class); Assert.assertEquals(query, serdeQuery); }
new DefaultLimitSpec( ImmutableList.of( new OrderByColumnSpec( "d0", OrderByColumnSpec.Direction.DESCENDING,
@Test public void testRejectForceLimitPushDownWithHaving() { expectedException.expect(IAE.class); expectedException.expectMessage("Cannot force limit push down when a having spec is present."); GroupByQuery .builder() .setDataSource(QueryRunnerTestHelper.dataSource) .setGranularity(QueryRunnerTestHelper.allGran) .setDimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.marketDimension, "marketalias")) .setInterval(QueryRunnerTestHelper.fullOnIntervalSpec) .setLimitSpec( new DefaultLimitSpec( Collections.singletonList(new OrderByColumnSpec("marketalias", OrderByColumnSpec.Direction.DESCENDING)), 2 ) ) .setAggregatorSpecs(QueryRunnerTestHelper.rowsCount) .setContext(ImmutableMap.of(GroupByQueryConfig.CTX_KEY_FORCE_LIMIT_PUSH_DOWN, true)) .setHavingSpec(new GreaterThanHavingSpec("rows", 10)) .build(); }
.setLimitSpec( new DefaultLimitSpec( Collections.singletonList(new OrderByColumnSpec( "constant", OrderByColumnSpec.Direction.DESCENDING
new DefaultLimitSpec( Collections.singletonList( new OrderByColumnSpec(QueryRunnerTestHelper.marketDimension, OrderByColumnSpec.Direction.DESCENDING) ),
new DefaultLimitSpec( ImmutableList.of( new OrderByColumnSpec( "d0", OrderByColumnSpec.Direction.ASCENDING,
new DefaultLimitSpec( Collections.singletonList( new OrderByColumnSpec("a0", Direction.ASCENDING, StringComparators.NUMERIC) ), Integer.MAX_VALUE
new DefaultLimitSpec( ImmutableList.of( new OrderByColumnSpec( "d0", OrderByColumnSpec.Direction.ASCENDING,
new DefaultLimitSpec( Collections.singletonList( new OrderByColumnSpec("a0", Direction.ASCENDING, StringComparators.NUMERIC) ), Integer.MAX_VALUE
new DefaultLimitSpec( ImmutableList.of( new OrderByColumnSpec("d1", OrderByColumnSpec.Direction.ASCENDING) ),
.setLimitSpec( new DefaultLimitSpec( Collections.singletonList(new OrderByColumnSpec( "alias", OrderByColumnSpec.Direction.DESCENDING
.setLimitSpec( new DefaultLimitSpec( ImmutableList.of(new OrderByColumnSpec("alias", OrderByColumnSpec.Direction.ASCENDING)), null