Search in sources :

Example 1 with RecordQueryPlanWithComparisons

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithComparisons in project fdb-record-layer by FoundationDB.

the class UnmatchedFieldsCountProperty method evaluateAtExpression.

@Nonnull
@Override
public Integer evaluateAtExpression(@Nonnull RelationalExpression expression, @Nonnull List<Integer> childResults) {
    int total = 0;
    for (Integer result : childResults) {
        if (result != null) {
            total += result;
        }
    }
    if (expression instanceof RecordQueryCoveringIndexPlan) {
        expression = ((RecordQueryCoveringIndexPlan) expression).getIndexPlan();
    }
    final int columnSize;
    if (expression instanceof RecordQueryPlanWithComparisons) {
        final ScanComparisons comparisons = ((RecordQueryPlanWithComparisons) expression).getComparisons();
        if (expression instanceof RecordQueryPlanWithIndex) {
            final String indexName = ((RecordQueryPlanWithIndex) expression).getIndexName();
            columnSize = planContext.getIndexByName(indexName).getRootExpression().getColumnSize();
        } else if (expression instanceof RecordQueryScanPlan) {
            columnSize = planContext.getGreatestPrimaryKeyWidth();
        } else {
            throw new RecordCoreException("unhandled plan with comparisons: can't find key expression");
        }
        return total + columnSize - (comparisons.getEqualitySize() + (comparisons.isEquality() ? 0 : 1));
    } else {
        return total;
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) ScanComparisons(com.apple.foundationdb.record.query.plan.ScanComparisons) RecordQueryPlanWithComparisons(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithComparisons) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) RecordQueryPlanWithIndex(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex) Nonnull(javax.annotation.Nonnull)

Aggregations

RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 ScanComparisons (com.apple.foundationdb.record.query.plan.ScanComparisons)1 RecordQueryCoveringIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan)1 RecordQueryPlanWithComparisons (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithComparisons)1 RecordQueryPlanWithIndex (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex)1 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)1 Nonnull (javax.annotation.Nonnull)1