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;
}
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;
}
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);
});
}
}
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();
}
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();
}
Aggregations