Search in sources :

Example 6 with ReaderContext

use of io.crate.execution.engine.fetch.ReaderContext in project crate by crate.

the class LongColumnReferenceTest method testLongExpression.

@Test
public void testLongExpression() throws Exception {
    LongColumnReference longColumn = new LongColumnReference(column);
    longColumn.startCollect(ctx);
    longColumn.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    long l = Long.MIN_VALUE;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        longColumn.setNextDocId(doc.doc);
        assertThat(longColumn.value(), is(l));
        l++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Example 7 with ReaderContext

use of io.crate.execution.engine.fetch.ReaderContext in project crate by crate.

the class StringColumnReferenceTest method testFieldCacheExpression.

@Test
public void testFieldCacheExpression() throws Exception {
    BytesRefColumnReference bytesRefColumn = new BytesRefColumnReference(column);
    bytesRefColumn.startCollect(ctx);
    bytesRefColumn.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    int i = 0;
    StringBuilder builder = new StringBuilder();
    for (ScoreDoc doc : topDocs.scoreDocs) {
        builder.append(i);
        bytesRefColumn.setNextDocId(doc.doc);
        assertThat(bytesRefColumn.value(), is(builder.toString()));
        i++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Example 8 with ReaderContext

use of io.crate.execution.engine.fetch.ReaderContext in project crate by crate.

the class LuceneBatchIterator method tryAdvanceDocIdSetIterator.

private boolean tryAdvanceDocIdSetIterator() throws IOException {
    if (currentDocIdSetIt != null) {
        return true;
    }
    while (leavesIt.hasNext()) {
        LeafReaderContext leaf = leavesIt.next();
        Scorer scorer = weight.scorer(leaf);
        if (scorer == null) {
            continue;
        }
        currentScorer = scorer;
        currentLeaf = leaf;
        currentDocIdSetIt = scorer.iterator();
        var readerContext = new ReaderContext(currentLeaf);
        for (LuceneCollectorExpression<?> expression : expressions) {
            expression.setScorer(currentScorer);
            expression.setNextReader(readerContext);
        }
        return true;
    }
    return false;
}
Also used : ReaderContext(io.crate.execution.engine.fetch.ReaderContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Scorer(org.apache.lucene.search.Scorer)

Example 9 with ReaderContext

use of io.crate.execution.engine.fetch.ReaderContext in project crate by crate.

the class IpColumnReferenceTest method testIpExpression.

@Test
public void testIpExpression() throws Exception {
    IpColumnReference columnReference = new IpColumnReference(IP_COLUMN);
    columnReference.startCollect(ctx);
    columnReference.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 21);
    assertThat(topDocs.scoreDocs.length, is(21));
    int i = 0;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        columnReference.setNextDocId(doc.doc);
        if (i == 20) {
            assertThat(columnReference.value(), is(nullValue()));
        } else if (i < 10) {
            assertThat(columnReference.value(), is("192.168.0." + i));
        } else {
            assertThat(columnReference.value(), is("7bd0:8082:2df8:487e:e0df:e7b5:9362:" + Integer.toHexString(i)));
        }
        i++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) IpColumnReference(io.crate.expression.reference.doc.lucene.IpColumnReference) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Example 10 with ReaderContext

use of io.crate.execution.engine.fetch.ReaderContext in project crate by crate.

the class IpColumnReferenceTest method testIpExpressionOnArrayThrowsException.

@Test
public void testIpExpressionOnArrayThrowsException() throws Exception {
    IpColumnReference columnReference = new IpColumnReference(IP_ARRAY_COLUMN);
    columnReference.startCollect(ctx);
    columnReference.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10);
    ScoreDoc doc = topDocs.scoreDocs[0];
    columnReference.setNextDocId(doc.doc);
    expectedException.expect(GroupByOnArrayUnsupportedException.class);
    expectedException.expectMessage("Column \"ia\" has a value that is an array. Group by doesn't work on Arrays");
    columnReference.value();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) IpColumnReference(io.crate.expression.reference.doc.lucene.IpColumnReference) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Aggregations

ReaderContext (io.crate.execution.engine.fetch.ReaderContext)12 Test (org.junit.Test)9 IndexSearcher (org.apache.lucene.search.IndexSearcher)8 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)8 ScoreDoc (org.apache.lucene.search.ScoreDoc)8 TopDocs (org.apache.lucene.search.TopDocs)8 IpColumnReference (io.crate.expression.reference.doc.lucene.IpColumnReference)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 Scorer (org.apache.lucene.search.Scorer)2 GroupByOnArrayUnsupportedException (io.crate.exceptions.GroupByOnArrayUnsupportedException)1 AggregationContext (io.crate.execution.engine.aggregation.AggregationContext)1 BooleanColumnReference (io.crate.expression.reference.doc.lucene.BooleanColumnReference)1 BytesRefColumnReference (io.crate.expression.reference.doc.lucene.BytesRefColumnReference)1 DoubleColumnReference (io.crate.expression.reference.doc.lucene.DoubleColumnReference)1 FloatColumnReference (io.crate.expression.reference.doc.lucene.FloatColumnReference)1 LongColumnReference (io.crate.expression.reference.doc.lucene.LongColumnReference)1 ShortColumnReference (io.crate.expression.reference.doc.lucene.ShortColumnReference)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1