Search in sources :

Example 1 with OrderByCollectorExpression

use of io.crate.expression.reference.doc.lucene.OrderByCollectorExpression in project crate by crate.

the class OrderedLuceneBatchIteratorFactoryTest method createOrderedCollector.

private LuceneOrderedDocCollector createOrderedCollector(IndexSearcher searcher, int shardId) {
    CollectorContext collectorContext = new CollectorContext();
    List<LuceneCollectorExpression<?>> expressions = Collections.singletonList(new OrderByCollectorExpression(reference, orderBy, o -> o));
    return new LuceneOrderedDocCollector(new ShardId("dummy", UUIDs.randomBase64UUID(), shardId), searcher, new MatchAllDocsQuery(), null, false, // batchSize < 10 to have at least one searchMore call.
    5, RamAccounting.NO_ACCOUNTING, collectorContext, f -> null, new Sort(new SortedNumericSortField(columnName, SortField.Type.LONG, reverseFlags[0])), expressions, expressions);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) RowAccounting(io.crate.breaker.RowAccounting) LongType(io.crate.types.LongType) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) BatchIterator(io.crate.data.BatchIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito.doThrow(org.mockito.Mockito.doThrow) Document(org.apache.lucene.document.Document) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) ESTestCase(org.elasticsearch.test.ESTestCase) SortField(org.apache.lucene.search.SortField) OrderingByPosition(io.crate.execution.engine.sort.OrderingByPosition) Before(org.junit.Before) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) LongStream(java.util.stream.LongStream) Sort(org.apache.lucene.search.Sort) DirectoryReader(org.apache.lucene.index.DirectoryReader) Reference(io.crate.metadata.Reference) UUIDs(org.elasticsearch.common.UUIDs) Test(org.junit.Test) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RamAccounting(io.crate.breaker.RamAccounting) LuceneCollectorExpression(io.crate.expression.reference.doc.lucene.LuceneCollectorExpression) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) IndexWriter(org.apache.lucene.index.IndexWriter) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Row(io.crate.data.Row) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) OrderByCollectorExpression(io.crate.expression.reference.doc.lucene.OrderByCollectorExpression) DataTypes(io.crate.types.DataTypes) Matchers.is(org.hamcrest.Matchers.is) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Comparator(java.util.Comparator) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Collections(java.util.Collections) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField) IndexSearcher(org.apache.lucene.search.IndexSearcher) Mockito.mock(org.mockito.Mockito.mock) ShardId(org.elasticsearch.index.shard.ShardId) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField) OrderByCollectorExpression(io.crate.expression.reference.doc.lucene.OrderByCollectorExpression) Sort(org.apache.lucene.search.Sort) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) LuceneCollectorExpression(io.crate.expression.reference.doc.lucene.LuceneCollectorExpression)

Example 2 with OrderByCollectorExpression

use of io.crate.expression.reference.doc.lucene.OrderByCollectorExpression in project crate by crate.

the class DocInputFactory method extractImplementations.

public InputFactory.Context<? extends LuceneCollectorExpression<?>> extractImplementations(TransactionContext txnCtx, RoutedCollectPhase phase) {
    OrderBy orderBy = phase.orderBy();
    ReferenceResolver<? extends LuceneCollectorExpression<?>> refResolver;
    if (orderBy == null) {
        refResolver = referenceResolver;
    } else {
        refResolver = ref -> {
            if (orderBy.orderBySymbols().contains(ref)) {
                DataType<?> dataType = ref.valueType();
                return new OrderByCollectorExpression(ref, orderBy, dataType::sanitizeValue);
            }
            return referenceResolver.getImplementation(ref);
        };
    }
    InputFactory.Context<? extends LuceneCollectorExpression<?>> ctx = inputFactory.ctxForRefs(txnCtx, refResolver);
    ctx.add(phase.toCollect());
    return ctx;
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.expression.InputFactory) OrderByCollectorExpression(io.crate.expression.reference.doc.lucene.OrderByCollectorExpression)

Aggregations

OrderBy (io.crate.analyze.OrderBy)2 OrderByCollectorExpression (io.crate.expression.reference.doc.lucene.OrderByCollectorExpression)2 RamAccounting (io.crate.breaker.RamAccounting)1 RowAccounting (io.crate.breaker.RowAccounting)1 RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)1 BatchIterator (io.crate.data.BatchIterator)1 Row (io.crate.data.Row)1 OrderingByPosition (io.crate.execution.engine.sort.OrderingByPosition)1 InputFactory (io.crate.expression.InputFactory)1 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)1 LuceneCollectorExpression (io.crate.expression.reference.doc.lucene.LuceneCollectorExpression)1 Reference (io.crate.metadata.Reference)1 BatchIteratorTester (io.crate.testing.BatchIteratorTester)1 TestingHelpers.createReference (io.crate.testing.TestingHelpers.createReference)1 TestingRowConsumer (io.crate.testing.TestingRowConsumer)1 DataTypes (io.crate.types.DataTypes)1 LongType (io.crate.types.LongType)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1