use of com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison in project fdb-record-layer by FoundationDB.
the class RecordQueryPlanner method planNoFilterNoSort.
@Nullable
private ScoredPlan planNoFilterNoSort(PlanContext planContext, @Nullable Index index) {
if (index != null && (!indexTypes.getValueTypes().contains(index.getType()) || index.getRootExpression().createsDuplicates())) {
return null;
}
ScanComparisons scanComparisons = null;
if (index == null && planContext.query.getRecordTypes().size() == 1 && planContext.commonPrimaryKey != null && Key.Expressions.hasRecordTypePrefix(planContext.commonPrimaryKey)) {
// Can scan just the one requested record type.
final RecordTypeKeyComparison recordTypeKeyComparison = new RecordTypeKeyComparison(planContext.query.getRecordTypes().iterator().next());
scanComparisons = new ScanComparisons.Builder().addEqualityComparison(recordTypeKeyComparison.getComparison()).build();
}
return new ScoredPlan(0, valueScan(new CandidateScan(planContext, index, false), scanComparisons, false));
}
use of com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method mergeRecordTypeAndComponent.
@Nonnull
protected static QueryComponent mergeRecordTypeAndComponent(@Nonnull String recordType, @Nullable QueryComponent component) {
if (component == null) {
return new RecordTypeKeyComparison(recordType);
}
List<QueryComponent> components = new ArrayList<>();
components.add(new RecordTypeKeyComparison(recordType));
if (component instanceof AndComponent) {
components.addAll(((AndComponent) component).getChildren());
} else {
components.add(component);
}
return Query.and(components);
}
use of com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison in project fdb-record-layer by FoundationDB.
the class RecordTypeKeyTest method testIndexScanOnSecondColumn.
@Test
@Disabled
public void testIndexScanOnSecondColumn() throws Exception {
final Index index = new Index("recno-type", concat(field("num_value_2"), recordType()));
RecordMetaDataHook hook = metaData -> {
BASIC_HOOK.apply(metaData);
metaData.addUniversalIndex(index);
};
List<FDBStoredRecord<Message>> recs = saveSomeRecords(hook);
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(2)).build();
// RecordQueryPlan plan = planner.plan(query);
ScanComparisons comparison = new ScanComparisons(Arrays.asList(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, 2), new RecordTypeKeyComparison("MySimpleRecord").getComparison()), Collections.emptySet());
IndexScanParameters scan = IndexScanComparisons.byValue(comparison);
RecordQueryPlan plan = new RecordQueryIndexPlan(index.getName(), scan, false);
assertEquals(recs.subList(1, 2), recordStore.executeQuery(query).map(FDBQueriedRecord::getStoredRecord).asList().join());
assertThat(plan, indexScan(allOf(indexName(index.getName()), bounds(hasTupleString("[EQUALS 2, IS MySimpleRecord]")))));
}
}
use of com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testUnexpected.
@Test
public void testUnexpected() {
// Make sure the places that throw an error when given an unknown expression all do so.
assertUnexpected(queryField("a").equalsValue(1), UnknownKeyExpression.UNKNOWN);
assertUnexpected(queryField("a").oneOfThem().equalsValue(1), UnknownKeyExpression.UNKNOWN);
assertUnexpected(queryField("p").matches(queryField("b").equalsValue(1)), UnknownKeyExpression.UNKNOWN);
assertUnexpected(queryField("p").oneOfThem().matches(queryField("b").equalsValue(1)), UnknownKeyExpression.UNKNOWN);
assertUnexpected(queryField("p").matches(queryField("b").equalsValue(1)), keyField("p").nest(UnknownKeyExpression.UNKNOWN));
assertUnexpected(queryField("p").oneOfThem().matches(queryField("b").equalsValue(1)), keyField("p", FanType.FanOut).nest(UnknownKeyExpression.UNKNOWN));
assertUnexpected(Query.and(Query.field("a").equalsValue(1), Query.field("b").equalsValue(2)), concat(keyField("a"), UnknownKeyExpression.UNKNOWN));
assertUnexpected(new RecordTypeKeyComparison("DummyRecordType"), UnknownKeyExpression.UNKNOWN);
}
use of com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testThen.
@Test
public void testThen() {
assertEquality(MatchType.EQUALITY, queryField("a").equalsValue(1), concatenateFields("a", "b"));
assertEquality(MatchType.NO_MATCH, queryField("a").equalsValue(1), concatenateFields("b", "a"));
assertEqualityCoveringKey(MatchType.NO_MATCH, queryField("a").equalsValue(1), concatenateFields("a", "b"));
assertEquality(MatchType.EQUALITY, queryField("a").oneOfThem().equalsValue(1), concat(keyField("a", FanType.FanOut), keyField("b")));
assertEquality(MatchType.NO_MATCH, queryField("a").oneOfThem().equalsValue(1), concat(keyField("b"), keyField("a", FanType.FanOut)));
assertEqualityCoveringKey(MatchType.NO_MATCH, queryField("a").oneOfThem().equalsValue(1), concat(keyField("a", FanType.FanOut), keyField("b")));
assertEquality(MatchType.EQUALITY, new RecordTypeKeyComparison("ErsatzRecordType"), concat(recordType(), keyField("a")));
assertEquality(MatchType.NO_MATCH, new RecordTypeKeyComparison("ErsatzRecordType"), concat(keyField("a"), recordType()));
assertEqualityCoveringKey(MatchType.NO_MATCH, new RecordTypeKeyComparison("ErsatzRecordType"), concat(recordType(), keyField("a")));
}
Aggregations