Search in sources :

Example 1 with RexChecker

use of org.apache.calcite.rex.RexChecker in project calcite by apache.

the class Window method isValid.

@Override
public boolean isValid(Litmus litmus, Context context) {
    // In the window specifications, an aggregate call such as
    // 'SUM(RexInputRef #10)' refers to expression #10 of inputProgram.
    // (Not its projections.)
    final RelDataType childRowType = getInput().getRowType();
    final int childFieldCount = childRowType.getFieldCount();
    final int inputSize = childFieldCount + constants.size();
    final List<RelDataType> inputTypes = new AbstractList<RelDataType>() {

        @Override
        public RelDataType get(int index) {
            return index < childFieldCount ? childRowType.getFieldList().get(index).getType() : constants.get(index - childFieldCount).getType();
        }

        @Override
        public int size() {
            return inputSize;
        }
    };
    final RexChecker checker = new RexChecker(inputTypes, context, litmus);
    int count = 0;
    for (Group group : groups) {
        for (RexWinAggCall over : group.aggCalls) {
            ++count;
            if (!checker.isValid(over)) {
                return litmus.fail(null);
            }
        }
    }
    if (count == 0) {
        return litmus.fail("empty");
    }
    return litmus.succeed();
}
Also used : AbstractList(java.util.AbstractList) RelDataType(org.apache.calcite.rel.type.RelDataType) RexChecker(org.apache.calcite.rex.RexChecker)

Example 2 with RexChecker

use of org.apache.calcite.rex.RexChecker in project calcite by apache.

the class Join method isValid.

@Override
public boolean isValid(Litmus litmus, Context context) {
    if (!super.isValid(litmus, context)) {
        return false;
    }
    if (getRowType().getFieldCount() != getSystemFieldList().size() + left.getRowType().getFieldCount() + (this instanceof SemiJoin ? 0 : right.getRowType().getFieldCount())) {
        return litmus.fail("field count mismatch");
    }
    if (condition != null) {
        if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) {
            return litmus.fail("condition must be boolean: {}", condition.getType());
        }
        // The input to the condition is a row type consisting of system
        // fields, left fields, and right fields. Very similar to the
        // output row type, except that fields have not yet been made due
        // due to outer joins.
        RexChecker checker = new RexChecker(getCluster().getTypeFactory().builder().addAll(getSystemFieldList()).addAll(getLeft().getRowType().getFieldList()).addAll(getRight().getRowType().getFieldList()).build(), context, litmus);
        condition.accept(checker);
        if (checker.getFailureCount() > 0) {
            return litmus.fail(checker.getFailureCount() + " failures in condition " + condition);
        }
    }
    return litmus.succeed();
}
Also used : RexChecker(org.apache.calcite.rex.RexChecker)

Example 3 with RexChecker

use of org.apache.calcite.rex.RexChecker in project calcite by apache.

the class Filter method isValid.

@Override
public boolean isValid(Litmus litmus, Context context) {
    if (RexUtil.isNullabilityCast(getCluster().getTypeFactory(), condition)) {
        return litmus.fail("Cast for just nullability not allowed");
    }
    final RexChecker checker = new RexChecker(getInput().getRowType(), context, litmus);
    condition.accept(checker);
    if (checker.getFailureCount() > 0) {
        return litmus.fail(null);
    }
    return litmus.succeed();
}
Also used : RexChecker(org.apache.calcite.rex.RexChecker)

Example 4 with RexChecker

use of org.apache.calcite.rex.RexChecker in project drill by apache.

the class JoinPrel method isValid.

/**
 * A Drill physical rel which is semi join will have output row type with fields from only
 * left side of the join. Calcite's join rel expects to have the output row type from
 * left and right side of the join. This function is overloaded to not throw exceptions for
 * a Drill semi join physical rel.
 */
@Override
public boolean isValid(Litmus litmus, Context context) {
    if (!this.isSemiJoin && !super.isValid(litmus, context)) {
        return false;
    }
    if (getRowType().getFieldCount() != getSystemFieldList().size() + left.getRowType().getFieldCount() + (this.isSemiJoin ? 0 : right.getRowType().getFieldCount())) {
        return litmus.fail("field count mismatch");
    }
    if (condition != null) {
        if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) {
            return litmus.fail("condition must be boolean: {}", condition.getType());
        }
        // The input to the condition is a row type consisting of system
        // fields, left fields, and right fields. Very similar to the
        // output row type, except that fields have not yet been made due
        // due to outer joins.
        RexChecker checker = new RexChecker(new RelDataTypeFactory.Builder(getCluster().getTypeFactory()).addAll(getSystemFieldList()).addAll(getLeft().getRowType().getFieldList()).addAll(getRight().getRowType().getFieldList()).build(), context, litmus);
        condition.accept(checker);
        if (checker.getFailureCount() > 0) {
            return litmus.fail(checker.getFailureCount() + " failures in condition " + condition);
        }
    }
    return litmus.succeed();
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RexChecker(org.apache.calcite.rex.RexChecker)

Example 5 with RexChecker

use of org.apache.calcite.rex.RexChecker in project drill by apache.

the class RowKeyJoinRel method isValid.

/**
 * The parent method relies the class being an instance of {@link org.apache.calcite.rel.core.SemiJoin}
 * in deciding row-type validity. We override this method to account for the RowKeyJoinRel logical rel
 * representing both regular and semi-joins
 */
@Override
public boolean isValid(Litmus litmus, Context context) {
    if (getRowType().getFieldCount() != getSystemFieldList().size() + left.getRowType().getFieldCount() + ((this.isSemiJoin()) ? 0 : right.getRowType().getFieldCount())) {
        return litmus.fail("field count mismatch");
    }
    if (condition != null) {
        if (condition.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) {
            return litmus.fail("condition must be boolean: {}", condition.getType());
        }
        // The input to the condition is a row type consisting of system
        // fields, left fields, and right fields. Very similar to the
        // output row type, except that fields have not yet been made due
        // due to outer joins.
        RexChecker checker = new RexChecker(getCluster().getTypeFactory().builder().addAll(getSystemFieldList()).addAll(getLeft().getRowType().getFieldList()).addAll(getRight().getRowType().getFieldList()).build(), context, litmus);
        condition.accept(checker);
        if (checker.getFailureCount() > 0) {
            return litmus.fail(checker.getFailureCount() + " failures in condition " + condition);
        }
    }
    return litmus.succeed();
}
Also used : RexChecker(org.apache.calcite.rex.RexChecker)

Aggregations

RexChecker (org.apache.calcite.rex.RexChecker)5 AbstractList (java.util.AbstractList)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1