Search in sources :

Example 11 with IndexScanType

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

the class LuceneIndexQueryPlan method executePlan.

/**
 * Override here to have specific logic to build the {@link QueryResult} for lucene auto complete suggestion result.
 */
@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    final RecordMetaData metaData = store.getRecordMetaData();
    final Index index = metaData.getIndex(indexName);
    final Collection<RecordType> recordTypes = metaData.recordTypesForIndex(index);
    if (recordTypes.size() != 1) {
        throw new RecordCoreException("No lucene index should span multiple record types");
    }
    final IndexScanType scanType = getScanType();
    if (scanType == IndexScanType.BY_LUCENE_AUTO_COMPLETE || scanType == IndexScanType.BY_LUCENE_SPELLCHECK) {
        final RecordType recordType = recordTypes.iterator().next();
        final RecordCursor<IndexEntry> entryRecordCursor = executeEntries(store, context, continuation, executeProperties);
        return entryRecordCursor.map(QueryPlanUtils.getCoveringIndexEntryToPartialRecordFunction(store, recordType.getName(), indexName, getToPartialRecord(index, recordType, scanType), scanType)).map(QueryResult::of);
    }
    return super.executePlan(store, context, continuation, executeProperties);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) RecordType(com.apple.foundationdb.record.metadata.RecordType) IndexScanType(com.apple.foundationdb.record.IndexScanType) IndexEntry(com.apple.foundationdb.record.IndexEntry) Index(com.apple.foundationdb.record.metadata.Index) Nonnull(javax.annotation.Nonnull)

Example 12 with IndexScanType

use of com.apple.foundationdb.record.IndexScanType 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;
}
Also used : IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) ScanComparisons(com.apple.foundationdb.record.query.plan.ScanComparisons) IndexScanType(com.apple.foundationdb.record.IndexScanType) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) ScanComparisons(com.apple.foundationdb.record.query.plan.ScanComparisons) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression)

Example 13 with IndexScanType

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

the class QueryPlanUtils method getCoveringIndexEntryToPartialRecordFunction.

/**
 * The method to get a function from an {@link IndexEntry} to a {@link FDBQueriedRecord} representing a partial record.
 */
@SuppressWarnings("unchecked")
public static <M extends Message> Function<IndexEntry, FDBQueriedRecord<M>> getCoveringIndexEntryToPartialRecordFunction(@Nonnull final FDBRecordStoreBase<M> store, @Nonnull final String recordTypeName, @Nonnull final String indexName, @Nonnull final IndexKeyValueToPartialRecord toRecord, @Nonnull final IndexScanType scanType) {
    final RecordMetaData metaData = store.getRecordMetaData();
    final RecordType recordType = metaData.getRecordType(recordTypeName);
    final Index index = metaData.getIndex(indexName);
    final Descriptors.Descriptor recordDescriptor = recordType.getDescriptor();
    boolean hasPrimaryKey = scanType != IndexScanType.BY_GROUP && scanType != IndexScanType.BY_LUCENE_AUTO_COMPLETE && scanType != IndexScanType.BY_LUCENE_SPELLCHECK;
    return indexEntry -> store.coveredIndexQueriedRecord(index, indexEntry, recordType, (M) toRecord.toRecord(recordDescriptor, indexEntry), hasPrimaryKey);
}
Also used : IndexEntry(com.apple.foundationdb.record.IndexEntry) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) IndexScanType(com.apple.foundationdb.record.IndexScanType) RecordType(com.apple.foundationdb.record.metadata.RecordType) IndexKeyValueToPartialRecord(com.apple.foundationdb.record.query.plan.IndexKeyValueToPartialRecord) Index(com.apple.foundationdb.record.metadata.Index) Descriptors(com.google.protobuf.Descriptors) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) Nonnull(javax.annotation.Nonnull) Function(java.util.function.Function) FDBRecordStoreBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordType(com.apple.foundationdb.record.metadata.RecordType) Index(com.apple.foundationdb.record.metadata.Index) Descriptors(com.google.protobuf.Descriptors)

Aggregations

IndexScanType (com.apple.foundationdb.record.IndexScanType)13 IndexEntry (com.apple.foundationdb.record.IndexEntry)12 Nonnull (javax.annotation.Nonnull)12 Index (com.apple.foundationdb.record.metadata.Index)11 RecordCursor (com.apple.foundationdb.record.RecordCursor)10 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)10 ScanProperties (com.apple.foundationdb.record.ScanProperties)10 TupleRange (com.apple.foundationdb.record.TupleRange)10 GroupingKeyExpression (com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression)10 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)10 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)9 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)9 FunctionNames (com.apple.foundationdb.record.FunctionNames)9 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)9 IndexAggregateFunction (com.apple.foundationdb.record.metadata.IndexAggregateFunction)9 IndexOptions (com.apple.foundationdb.record.metadata.IndexOptions)9 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)9 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)9 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)9 PlanHashable (com.apple.foundationdb.record.PlanHashable)8