use of com.apple.foundationdb.record.query.plan.ScanComparisons in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreTest method testOverlappingPrimaryKey.
@Test
public void testOverlappingPrimaryKey() {
try (FDBRecordContext context = openContext()) {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecordsWithHeaderProto.getDescriptor());
builder.getRecordType("MyRecord").setPrimaryKey(field("header").nest(concatenateFields("path", "rec_no")));
builder.addIndex("MyRecord", "MyRecord$path_str", concat(field("header").nest("path"), field("str_value")));
RecordMetaData metaData = builder.getRecordMetaData();
createOrOpenRecordStore(context, metaData);
TestRecordsWithHeaderProto.MyRecord.Builder recBuilder = TestRecordsWithHeaderProto.MyRecord.newBuilder();
TestRecordsWithHeaderProto.HeaderRecord.Builder headerBuilder = recBuilder.getHeaderBuilder();
headerBuilder.setPath("aaa");
headerBuilder.setRecNo(1);
recBuilder.setStrValue("hello");
recordStore.saveRecord(recBuilder.build());
headerBuilder.setPath("aaa");
headerBuilder.setRecNo(2);
recBuilder.setStrValue("goodbye");
recordStore.saveRecord(recBuilder.build());
headerBuilder.setPath("zzz");
headerBuilder.setRecNo(3);
recBuilder.setStrValue("end");
recordStore.saveRecord(recBuilder.build());
List<List<Object>> rows = new ArrayList<>();
Index index = metaData.getIndex("MyRecord$path_str");
ScanComparisons comparisons = ScanComparisons.from(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, "aaa"));
TupleRange range = comparisons.toTupleRange();
try (RecordCursor<IndexEntry> cursor = recordStore.scanIndex(index, IndexScanType.BY_VALUE, range, null, ScanProperties.FORWARD_SCAN)) {
cursor.forEach(row -> rows.add(row.getKey().getItems())).join();
}
assertEquals(Arrays.asList(Arrays.asList("aaa", "goodbye", 2L), Arrays.asList("aaa", "hello", 1L)), rows);
}
}
use of com.apple.foundationdb.record.query.plan.ScanComparisons in project fdb-record-layer by FoundationDB.
the class QueryPlanCursorTest method reverse.
@Test
public void reverse() throws Exception {
final IndexScanParameters scan = IndexScanComparisons.byValue(new ScanComparisons(Collections.emptyList(), ImmutableSet.of(new Comparisons.SimpleComparison(Comparisons.Type.GREATER_THAN, 2), new Comparisons.SimpleComparison(Comparisons.Type.LESS_THAN, 4))));
final RecordQueryPlan plan = new RecordQueryIndexPlan("MySimpleRecord$num_value_3_indexed", scan, true);
compareSkipsAndCursors(plan);
}
use of com.apple.foundationdb.record.query.plan.ScanComparisons in project fdb-record-layer by FoundationDB.
the class QueryPlanCursorTest method in.
@Test
public void in() throws Exception {
final IndexScanParameters scan = IndexScanComparisons.byValue(new ScanComparisons(Arrays.asList(new Comparisons.ParameterComparison(Comparisons.Type.EQUALS, "in_num")), Collections.emptySet()));
final RecordQueryPlan plan = new RecordQueryInValuesJoinPlan(new RecordQueryIndexPlan("MySimpleRecord$num_value_3_indexed", scan, false), "in_num", Bindings.Internal.IN, Arrays.asList(2, 4), false, false);
compareSkipsAndCursors(plan);
}
use of com.apple.foundationdb.record.query.plan.ScanComparisons 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.plan.ScanComparisons in project fdb-record-layer by FoundationDB.
the class LuceneIndexQueryPlan method merge.
public static LuceneIndexQueryPlan merge(LuceneIndexQueryPlan plan1, LuceneIndexQueryPlan plan2, String type) {
verify(plan1.indexName.equals(plan2.indexName));
verify(plan1.sort == null || plan2.sort == null || plan1.sort.equals(plan2.sort));
KeyExpression newSort = plan1.sort != null ? plan1.sort : plan2.sort;
String newQuery = String.format("(%s) %s (%s)", plan1.getLuceneQueryString(), type, plan2.getLuceneQueryString());
Comparisons.LuceneComparison comparison = new Comparisons.LuceneComparison(newQuery);
boolean newReverse = plan1.isReverse() ? plan1.isReverse() : plan2.isReverse();
IndexScanType scanType = IndexScanType.BY_LUCENE;
if (plan1.getScanType() == IndexScanType.BY_LUCENE_FULL_TEXT || plan2.getScanType() == IndexScanType.BY_LUCENE_FULL_TEXT) {
scanType = IndexScanType.BY_LUCENE_FULL_TEXT;
}
ScanComparisons newGrouping = plan1.groupingComparisons == null ? ScanComparisons.EMPTY : plan1.groupingComparisons;
if (newGrouping.isEmpty()) {
newGrouping = plan2.groupingComparisons;
} else if (plan2.groupingComparisons != null) {
newGrouping = newGrouping.merge(plan2.groupingComparisons);
}
LuceneIndexQueryPlan plan = new LuceneIndexQueryPlan(plan1.indexName, scanType, comparison, newReverse, newSort, newGrouping);
if (plan1.createsDuplicates() || plan2.createsDuplicates()) {
plan.setCreatesDuplicates();
}
return plan;
}
Aggregations