Search in sources :

Example 26 with OrderByColumnSpec

use of io.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.

the class DruidQueryBuilder method toSelectQuery.

/**
   * Return this query as a Select query, or null if this query is not compatible with Select.
   *
   * @param dataSource         data source to query
   * @param sourceRowSignature row signature of the dataSource
   * @param context            query context
   *
   * @return query or null
   */
public SelectQuery toSelectQuery(final DataSource dataSource, final RowSignature sourceRowSignature, final Map<String, Object> context) {
    if (grouping != null) {
        return null;
    }
    final Filtration filtration = Filtration.create(filter).optimize(sourceRowSignature);
    final boolean descending;
    if (limitSpec != null) {
        // Safe to assume limitSpec has zero or one entry; DruidSelectSortRule wouldn't push in anything else.
        if (limitSpec.getColumns().size() > 0) {
            final OrderByColumnSpec orderBy = Iterables.getOnlyElement(limitSpec.getColumns());
            if (!orderBy.getDimension().equals(Column.TIME_COLUMN_NAME)) {
                throw new ISE("WTF?! Got select with non-time orderBy[%s]", orderBy);
            }
            descending = orderBy.getDirection() == OrderByColumnSpec.Direction.DESCENDING;
        } else {
            descending = false;
        }
    } else {
        descending = false;
    }
    return new SelectQuery(dataSource, filtration.getQuerySegmentSpec(), descending, filtration.getDimFilter(), Granularities.ALL, selectProjection != null ? selectProjection.getDimensions() : ImmutableList.<DimensionSpec>of(), selectProjection != null ? selectProjection.getMetrics() : ImmutableList.<String>of(), null, new PagingSpec(null, 0), /* dummy -- will be replaced */
    context);
}
Also used : OrderByColumnSpec(io.druid.query.groupby.orderby.OrderByColumnSpec) SelectQuery(io.druid.query.select.SelectQuery) DimensionSpec(io.druid.query.dimension.DimensionSpec) Filtration(io.druid.sql.calcite.filtration.Filtration) PagingSpec(io.druid.query.select.PagingSpec) ISE(io.druid.java.util.common.ISE)

Example 27 with OrderByColumnSpec

use of io.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.

the class DruidQueryBuilder method getRelTraits.

public RelTrait[] getRelTraits() {
    final List<RelFieldCollation> collations = Lists.newArrayList();
    if (limitSpec != null) {
        for (OrderByColumnSpec orderBy : limitSpec.getColumns()) {
            final int i = outputRowSignature.getRowOrder().indexOf(orderBy.getDimension());
            final RelFieldCollation.Direction direction = orderBy.getDirection() == OrderByColumnSpec.Direction.ASCENDING ? RelFieldCollation.Direction.ASCENDING : RelFieldCollation.Direction.DESCENDING;
            collations.add(new RelFieldCollation(i, direction));
        }
    }
    if (!collations.isEmpty()) {
        return new RelTrait[] { RelCollations.of(collations) };
    } else {
        return new RelTrait[] {};
    }
}
Also used : OrderByColumnSpec(io.druid.query.groupby.orderby.OrderByColumnSpec) RelTrait(org.apache.calcite.plan.RelTrait) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Aggregations

OrderByColumnSpec (io.druid.query.groupby.orderby.OrderByColumnSpec)27 Test (org.junit.Test)22 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)21 Row (io.druid.data.input.Row)19 DefaultLimitSpec (io.druid.query.groupby.orderby.DefaultLimitSpec)19 DimensionSpec (io.druid.query.dimension.DimensionSpec)15 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)13 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)10 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)9 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)9 PostAggregator (io.druid.query.aggregation.PostAggregator)7 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)6 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)6 FieldAccessPostAggregator (io.druid.query.aggregation.post.FieldAccessPostAggregator)6 JavaScriptAggregatorFactory (io.druid.query.aggregation.JavaScriptAggregatorFactory)5 HyperUniqueFinalizingPostAggregator (io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator)5 ArithmeticPostAggregator (io.druid.query.aggregation.post.ArithmeticPostAggregator)5 ConstantPostAggregator (io.druid.query.aggregation.post.ConstantPostAggregator)5 ExpressionPostAggregator (io.druid.query.aggregation.post.ExpressionPostAggregator)5 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)4