Search in sources :

Example 1 with KeyConstraint

use of io.confluent.ksql.planner.plan.KeyConstraint in project ksql by confluentinc.

the class KeyedTableLookupOperator method getMatIterator.

private Iterator<Row> getMatIterator(final KsqlKey ksqlKey) {
    if (!(nextKey instanceof KeyConstraint)) {
        throw new IllegalStateException(String.format("Keyed lookup queries should be done with " + "key constraints: %s", ksqlKey.toString()));
    }
    final KeyConstraint keyConstraintKey = (KeyConstraint) ksqlKey;
    final Iterator<Row> result;
    if (keyConstraintKey.getOperator() == ConstraintOperator.EQUAL) {
        result = mat.nonWindowed().get(ksqlKey.getKey(), nextLocation.getPartition(), consistencyOffsetVector);
    } else if (keyConstraintKey.getOperator() == ConstraintOperator.GREATER_THAN || keyConstraintKey.getOperator() == ConstraintOperator.GREATER_THAN_OR_EQUAL) {
        // Underlying store will always return keys inclusive the endpoints
        // and filtering is used to trim start and end of the range in case of ">"
        final GenericKey fromKey = keyConstraintKey.getKey();
        final GenericKey toKey = null;
        result = mat.nonWindowed().get(nextLocation.getPartition(), fromKey, toKey, consistencyOffsetVector);
    } else if (keyConstraintKey.getOperator() == ConstraintOperator.LESS_THAN || keyConstraintKey.getOperator() == ConstraintOperator.LESS_THAN_OR_EQUAL) {
        // Underlying store will always return keys inclusive the endpoints
        // and filtering is used to trim start and end of the range in case of "<"
        final GenericKey fromKey = null;
        final GenericKey toKey = keyConstraintKey.getKey();
        result = mat.nonWindowed().get(nextLocation.getPartition(), fromKey, toKey, consistencyOffsetVector);
    } else {
        throw new IllegalStateException(String.format("Invalid comparator type " + keyConstraintKey.getOperator()));
    }
    return result;
}
Also used : KeyConstraint(io.confluent.ksql.planner.plan.KeyConstraint) Row(io.confluent.ksql.execution.streams.materialization.Row) GenericKey(io.confluent.ksql.GenericKey)

Example 2 with KeyConstraint

use of io.confluent.ksql.planner.plan.KeyConstraint in project ksql by confluentinc.

the class PullPhysicalPlan method getKeys.

public List<KsqlKey> getKeys() {
    final List<KsqlKey> list = new ArrayList<>();
    for (LookupConstraint c : lookupConstraints) {
        if (c instanceof KeyConstraint) {
            final KeyConstraint kc = (KeyConstraint) c;
            list.add(kc.getKsqlKey());
        } else {
            // we shouldn't see any NonKeyContraints here
            return Collections.emptyList();
        }
    }
    return ImmutableList.copyOf(list);
}
Also used : LookupConstraint(io.confluent.ksql.planner.plan.LookupConstraint) KeyConstraint(io.confluent.ksql.planner.plan.KeyConstraint) KsqlKey(io.confluent.ksql.execution.streams.materialization.Locator.KsqlKey) ArrayList(java.util.ArrayList)

Aggregations

KeyConstraint (io.confluent.ksql.planner.plan.KeyConstraint)2 GenericKey (io.confluent.ksql.GenericKey)1 KsqlKey (io.confluent.ksql.execution.streams.materialization.Locator.KsqlKey)1 Row (io.confluent.ksql.execution.streams.materialization.Row)1 LookupConstraint (io.confluent.ksql.planner.plan.LookupConstraint)1 ArrayList (java.util.ArrayList)1