@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { EnumerableRel input = sole(inputs); if (input instanceof OLAPRel) { ((OLAPRel) input).replaceTraitSet(EnumerableConvention.INSTANCE); } return EnumerableLimit.create(input, localOffset, localFetch); }
public Result implement(EnumerableRelImplementor implementor, Prefer pref) { final BlockBuilder builder = new BlockBuilder(); final EnumerableRel child = (EnumerableRel) getInput(); final Result result = implementor.visitChild(this, 0, child, pref); final PhysType physType = PhysTypeImpl.of( implementor.getTypeFactory(), getRowType(), result.format); v, BuiltInMethod.SKIP.method, getExpression(offset))); v, BuiltInMethod.TAKE.method, getExpression(fetch)));
@Override public EnumerableLimit copy( RelTraitSet traitSet, List<RelNode> newInputs) { return new EnumerableLimit( getCluster(), traitSet, sole(newInputs), offset, fetch); }
public Double getMaxRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getMaxRowCount(rel.getInput()); if (rowCount == null) { rowCount = Double.POSITIVE_INFINITY; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
/** Creates an EnumerableLimit. */ public static EnumerableLimit create(final RelNode input, RexNode offset, RexNode fetch) { final RelOptCluster cluster = input.getCluster(); final RelMetadataQuery mq = cluster.getMetadataQuery(); final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE) .replaceIfs( RelCollationTraitDef.INSTANCE, () -> RelMdCollation.limit(mq, input)) .replaceIf(RelDistributionTraitDef.INSTANCE, () -> RelMdDistribution.limit(mq, input)); return new EnumerableLimit(cluster, traitSet, input, offset, fetch); }
/** Creates an EnumerableLimit. * * <p>Use {@link #create} unless you know what you're doing. */ public EnumerableLimit( RelOptCluster cluster, RelTraitSet traitSet, RelNode input, RexNode offset, RexNode fetch) { super(cluster, traitSet, input); this.offset = offset; this.fetch = fetch; assert getConvention() instanceof EnumerableConvention; assert getConvention() == input.getConvention(); }
public Result implement(EnumerableRelImplementor implementor, Prefer pref) { final BlockBuilder builder = new BlockBuilder(); final EnumerableRel child = (EnumerableRel) getInput(); final Result result = implementor.visitChild(this, 0, child, pref); final PhysType physType = PhysTypeImpl.of( implementor.getTypeFactory(), getRowType(), result.format); v, BuiltInMethod.SKIP.method, getExpression(offset))); v, BuiltInMethod.TAKE.method, getExpression(fetch)));
@Override public EnumerableLimit copy( RelTraitSet traitSet, List<RelNode> newInputs) { return new EnumerableLimit( getCluster(), traitSet, sole(newInputs), offset, fetch); }
public Double getMaxRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getMaxRowCount(rel.getInput()); if (rowCount == null) { rowCount = Double.POSITIVE_INFINITY; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
/** Creates an EnumerableLimit. */ public static EnumerableLimit create(final RelNode input, RexNode offset, RexNode fetch) { final RelOptCluster cluster = input.getCluster(); final RelMetadataQuery mq = cluster.getMetadataQuery(); final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE) .replaceIfs( RelCollationTraitDef.INSTANCE, () -> RelMdCollation.limit(mq, input)) .replaceIf(RelDistributionTraitDef.INSTANCE, () -> RelMdDistribution.limit(mq, input)); return new EnumerableLimit(cluster, traitSet, input, offset, fetch); }
/** Creates an EnumerableLimit. * * <p>Use {@link #create} unless you know what you're doing. */ public EnumerableLimit( RelOptCluster cluster, RelTraitSet traitSet, RelNode input, RexNode offset, RexNode fetch) { super(cluster, traitSet, input); this.offset = offset; this.fetch = fetch; assert getConvention() instanceof EnumerableConvention; assert getConvention() == input.getConvention(); }
public Double getMinRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getMinRowCount(rel.getInput()); if (rowCount == null) { rowCount = 0D; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
@Override public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); if (sort.offset == null && sort.fetch == null) { return; } final RelTraitSet traitSet = sort.getTraitSet().replace(EnumerableConvention.INSTANCE); RelNode input = sort.getInput(); if (!sort.getCollation().getFieldCollations().isEmpty()) { // Create a sort with the same sort key, but no offset or fetch. input = sort.copy( sort.getTraitSet(), input, sort.getCollation(), null, null); } RelNode x = convert( input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)); call.transformTo( new EnumerableLimit( sort.getCluster(), traitSet, x, sort.offset, sort.fetch)); } }
@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { EnumerableRel input = sole(inputs); if (input instanceof OLAPRel) { ((OLAPRel) input).replaceTraitSet(EnumerableConvention.INSTANCE); } return EnumerableLimit.create(input, localOffset, localFetch); }
public Double getMinRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getMinRowCount(rel.getInput()); if (rowCount == null) { rowCount = 0D; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
@Override public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); if (sort.offset == null && sort.fetch == null) { return; } final RelTraitSet traitSet = sort.getTraitSet().replace(EnumerableConvention.INSTANCE); RelNode input = sort.getInput(); if (!sort.getCollation().getFieldCollations().isEmpty()) { // Create a sort with the same sort key, but no offset or fetch. input = sort.copy( sort.getTraitSet(), input, sort.getCollation(), null, null); } RelNode x = convert( input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)); call.transformTo( new EnumerableLimit( sort.getCluster(), traitSet, x, sort.offset, sort.fetch)); } }
public Double getRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getRowCount(rel.getInput()); if (rowCount == null) { return null; } if (rel.offset instanceof RexDynamicParam) { return rowCount; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { if (rel.fetch instanceof RexDynamicParam) { return rowCount; } final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
public Double getRowCount(EnumerableLimit rel, RelMetadataQuery mq) { Double rowCount = mq.getRowCount(rel.getInput()); if (rowCount == null) { return null; } if (rel.offset instanceof RexDynamicParam) { return rowCount; } final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); rowCount = Math.max(rowCount - offset, 0D); if (rel.fetch != null) { if (rel.fetch instanceof RexDynamicParam) { return rowCount; } final int limit = RexLiteral.intValue(rel.fetch); if (limit < rowCount) { return (double) limit; } } return rowCount; }
private PlannerOp planLimit(EnumerableLimit op, RelDataType rowType) { PlannerOp input = convertRelNode(op.getInput(), rowType, false); CompiledSQLExpression maxRows = SQLExpressionCompiler.compileExpression(op.fetch); CompiledSQLExpression offset = SQLExpressionCompiler.compileExpression(op.offset); return new LimitOp(input, maxRows, offset); }