Search in sources :

Example 1 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class IntersectionCursorBase method createCursorStates.

@Nonnull
protected static <T> List<KeyedMergeCursorState<T>> createCursorStates(@Nonnull List<Function<byte[], RecordCursor<T>>> cursorFunctions, @Nullable byte[] byteContinuation, @Nonnull Function<? super T, ? extends List<Object>> comparisonKeyFunction) {
    if (cursorFunctions.size() < 2) {
        throw new RecordCoreArgumentException("not enough child cursors provided to IntersectionCursor").addLogInfo(LogMessageKeys.CHILD_COUNT, cursorFunctions.size());
    }
    final List<KeyedMergeCursorState<T>> cursorStates = new ArrayList<>(cursorFunctions.size());
    final IntersectionCursorContinuation continuation = IntersectionCursorContinuation.from(byteContinuation, cursorFunctions.size());
    int i = 0;
    for (Function<byte[], RecordCursor<T>> cursorFunction : cursorFunctions) {
        cursorStates.add(KeyedMergeCursorState.from(cursorFunction, continuation.getContinuations().get(i), comparisonKeyFunction));
        i++;
    }
    return cursorStates;
}
Also used : RecordCursor(com.apple.foundationdb.record.RecordCursor) ArrayList(java.util.ArrayList) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 2 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class JoinedRecordTypeBuilder method addJoin.

/**
 * Add a new join.
 * @param left the correlation name of the left constituent
 * @param leftExpression an expression to evaluate against the left constituent
 * @param right the correlation name of the right constituent
 * @param rightExpression an expression to evaluate against the right constituent
 * @return the newly added join
 */
@Nonnull
public Join addJoin(@Nonnull String left, @Nonnull KeyExpression leftExpression, @Nonnull String right, @Nonnull KeyExpression rightExpression) {
    if (leftExpression.getColumnSize() != rightExpression.getColumnSize()) {
        throw new RecordCoreArgumentException("Two sides of join are not the same size and will never match").addLogInfo("left", leftExpression, "right", rightExpression);
    }
    Join join = new Join(left, leftExpression, right, rightExpression);
    joins.add(join);
    return join;
}
Also used : RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 3 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class KeySpaceDirectory method getValueRange.

@Nonnull
private CompletableFuture<KeyRange> getValueRange(@Nonnull FDBRecordContext context, @Nullable ValueRange<?> valueRange, @Nonnull Subspace subspace) {
    final byte[] startKey;
    final byte[] stopKey;
    final EndpointType startType;
    final EndpointType stopType;
    if (getValue() == KeySpaceDirectory.ANY_VALUE) {
        if (valueRange != null && valueRange.getLowEndpoint() != EndpointType.TREE_START) {
            if (KeyType.typeOf(valueRange.getLow()) != getKeyType()) {
                throw invalidValueTypeException(KeyType.typeOf(valueRange.getLow()), getKeyType(), getName(), valueRange);
            }
            startKey = subspace.pack(valueRange.getLow());
            startType = valueRange.getLowEndpoint();
            if (startType != EndpointType.RANGE_INCLUSIVE && startType != EndpointType.RANGE_EXCLUSIVE) {
                throw new RecordCoreArgumentException("Endpoint type not supported for directory list", LogMessageKeys.ENDPOINT_TYPE, startType);
            }
        } else {
            final byte[] subspaceBytes = subspace.pack();
            startKey = new byte[subspaceBytes.length + 1];
            System.arraycopy(subspaceBytes, 0, startKey, 0, subspaceBytes.length);
            startKey[subspaceBytes.length] = getKeyType().getTypeLowBounds();
            startType = EndpointType.RANGE_INCLUSIVE;
        }
        if (valueRange != null && valueRange.getHighEndpoint() != EndpointType.TREE_END) {
            if (KeyType.typeOf(valueRange.getHigh()) != getKeyType()) {
                throw invalidValueTypeException(KeyType.typeOf(valueRange.getHigh()), getKeyType(), getName(), valueRange);
            }
            stopKey = subspace.pack(valueRange.getHigh());
            stopType = valueRange.getHighEndpoint();
            if (stopType != EndpointType.RANGE_INCLUSIVE && stopType != EndpointType.RANGE_EXCLUSIVE) {
                throw new RecordCoreArgumentException("Endpoint type not supported for directory list", LogMessageKeys.ENDPOINT_TYPE, stopType);
            }
        } else {
            final byte[] subspaceBytes = subspace.pack();
            stopKey = new byte[subspaceBytes.length + 1];
            System.arraycopy(subspaceBytes, 0, stopKey, 0, subspaceBytes.length);
            stopKey[subspaceBytes.length] = getKeyType().getTypeHighBounds();
            stopType = EndpointType.RANGE_EXCLUSIVE;
        }
        return CompletableFuture.completedFuture(new KeyRange(startKey, startType, stopKey, stopType));
    } else {
        if (valueRange != null) {
            throw new RecordCoreArgumentException("range is not applicable when the subdirectory has a value.", LogMessageKeys.DIR_NAME, getName(), LogMessageKeys.RANGE, valueRange);
        }
        return toTupleValueAsync(context, this.value).thenApply(resolvedValue -> {
            final byte[] key = subspace.pack(Tuple.from(resolvedValue.getResolvedValue()));
            return new KeyRange(key, EndpointType.RANGE_INCLUSIVE, ByteArrayUtil.strinc(key), EndpointType.RANGE_EXCLUSIVE);
        });
    }
}
Also used : KeyRange(com.apple.foundationdb.record.KeyRange) EndpointType(com.apple.foundationdb.record.EndpointType) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 4 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class TextIndexTest method queryMapDocumentsWithIndex.

@Nonnull
private List<Long> queryMapDocumentsWithIndex(@Nonnull String key, @Nonnull QueryComponent textFilter, int planHash, boolean isCoveringIndexExpected) throws InterruptedException, ExecutionException {
    if (!(textFilter instanceof ComponentWithComparison)) {
        throw new RecordCoreArgumentException("filter without comparison provided as text filter");
    }
    final QueryComponent filter = Query.field("entry").oneOfThem().matches(Query.and(Query.field("key").equalsValue(key), textFilter));
    Matcher<RecordQueryPlan> indexMatcher = textIndexScan(allOf(indexName(MAP_ON_VALUE_INDEX.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + key + "],[" + key + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))));
    if (isCoveringIndexExpected) {
        indexMatcher = coveringIndexScan(indexMatcher);
    }
    final Matcher<RecordQueryPlan> planMatcher = descendant(indexMatcher);
    return queryDocuments(Collections.singletonList(MAP_DOC), Collections.singletonList(field("doc_id")), filter, planHash, planMatcher).map(t -> t.getLong(0)).asList().get();
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) ComponentWithComparison(com.apple.foundationdb.record.query.expressions.ComponentWithComparison) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 5 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class TextIndexTest method queryMapDocumentsWithGroupedIndex.

@Nonnull
private List<Long> queryMapDocumentsWithGroupedIndex(@Nonnull String key, @Nonnull QueryComponent textFilter, long group, int planHash) throws InterruptedException, ExecutionException {
    if (!(textFilter instanceof ComponentWithComparison)) {
        throw new RecordCoreArgumentException("filter without comparison provided as text filter");
    }
    final QueryComponent filter = Query.and(Query.field("group").equalsValue(group), Query.field("entry").oneOfThem().matches(Query.and(Query.field("key").equalsValue(key), textFilter)));
    final Matcher<RecordQueryPlan> planMatcher = descendant(coveringIndexScan(textIndexScan(allOf(indexName(MAP_ON_VALUE_GROUPED_INDEX.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + group + ", " + key + "],[" + group + ", " + key + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))))));
    return queryDocuments(Collections.singletonList(MAP_DOC), Collections.singletonList(field("doc_id")), filter, planHash, planMatcher).map(t -> t.getLong(0)).asList().get();
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) ComponentWithComparison(com.apple.foundationdb.record.query.expressions.ComponentWithComparison) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Aggregations

RecordCoreArgumentException (com.apple.foundationdb.record.RecordCoreArgumentException)17 Nonnull (javax.annotation.Nonnull)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)4 ComponentWithComparison (com.apple.foundationdb.record.query.expressions.ComponentWithComparison)3 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)3 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 Tuple (com.apple.foundationdb.tuple.Tuple)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordCursor (com.apple.foundationdb.record.RecordCursor)2 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)2 Subspace (com.apple.foundationdb.subspace.Subspace)2 KeyValue (com.apple.foundationdb.KeyValue)1 ReadTransaction (com.apple.foundationdb.ReadTransaction)1 Transaction (com.apple.foundationdb.Transaction)1 API (com.apple.foundationdb.annotation.API)1 EndpointType (com.apple.foundationdb.record.EndpointType)1 KeyRange (com.apple.foundationdb.record.KeyRange)1 TupleRange (com.apple.foundationdb.record.TupleRange)1 CompletionExceptionLogHelper (com.apple.foundationdb.record.logging.CompletionExceptionLogHelper)1