Class KuduAggregationLimitRule

java.lang.Object
org.apache.calcite.plan.RelOptRule
com.twilio.kudu.sql.rules.KuduAggregationLimitRule

public class KuduAggregationLimitRule extends org.apache.calcite.plan.RelOptRule
Rule to match a limit over a sort over aggregation. There must be a common prefix between the sort columns and the primary key columns of the table. If a table has three columns A, B and C with a PK(A, B) this rule can be applied if sorting by (A, SUM(C)) and grouping by (A, B) with a limit. For eg: (A,B,C) (1, 1, 4), (1, 2, 2), (2, 1, 1). If we query with a limit of 2, then we can stop reading rows when we process the 3rd row as we will have 2 groups (1,1) and (1,2). This rule limits the number of rows read from kudu, but rows still need to be sorted on the client.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule

    org.apache.calcite.plan.RelOptRule.ConverterRelOptRuleOperand
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.apache.calcite.plan.RelOptRule
     

    Fields inherited from class org.apache.calcite.plan.RelOptRule

    description, operands, relBuilderFactory
  • Constructor Summary

    Constructors
    Constructor
    Description
    KuduAggregationLimitRule(org.apache.calcite.tools.RelBuilderFactory factory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    getSortPkPrefix(org.apache.calcite.rel.RelCollation newCollation, KuduQuery query, Optional<org.apache.calcite.rel.core.Filter> filter)
     
    void
    onMatch(org.apache.calcite.plan.RelOptRuleCall call)
     
    protected void
    perform(org.apache.calcite.plan.RelOptRuleCall call, org.apache.calcite.rel.core.Sort originalSort, org.apache.calcite.rel.core.Aggregate originalAggregate, org.apache.calcite.rel.core.Project project, org.apache.calcite.rel.core.Filter filter, KuduQuery query)
     

    Methods inherited from class org.apache.calcite.plan.RelOptRule

    any, convert, convert, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • AGGREGATION_LIMIT_RULE

      public static final org.apache.calcite.plan.RelOptRule AGGREGATION_LIMIT_RULE
  • Constructor Details

    • KuduAggregationLimitRule

      public KuduAggregationLimitRule(org.apache.calcite.tools.RelBuilderFactory factory)
  • Method Details

    • onMatch

      public void onMatch(org.apache.calcite.plan.RelOptRuleCall call)
      Specified by:
      onMatch in class org.apache.calcite.plan.RelOptRule
    • perform

      protected void perform(org.apache.calcite.plan.RelOptRuleCall call, org.apache.calcite.rel.core.Sort originalSort, org.apache.calcite.rel.core.Aggregate originalAggregate, org.apache.calcite.rel.core.Project project, org.apache.calcite.rel.core.Filter filter, KuduQuery query)
    • getSortPkPrefix

      public List<Integer> getSortPkPrefix(org.apache.calcite.rel.RelCollation newCollation, KuduQuery query, Optional<org.apache.calcite.rel.core.Filter> filter)