Search in sources :

Example 11 with ReaderContext

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

the class ShortColumnReferenceTest method testShortExpression.

@Test
public void testShortExpression() throws Exception {
    ShortColumnReference shortColumn = new ShortColumnReference(column);
    shortColumn.startCollect(ctx);
    shortColumn.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    short i = -10;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        shortColumn.setNextDocId(doc.doc);
        assertThat(shortColumn.value(), is(i));
        i++;
    }
}
Also used : ShortColumnReference(io.crate.expression.reference.doc.lucene.ShortColumnReference) IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Example 12 with ReaderContext

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

the class DoubleColumnReferenceTest method testFieldCacheExpression.

@Test
public void testFieldCacheExpression() throws Exception {
    DoubleColumnReference doubleColumn = new DoubleColumnReference(column);
    doubleColumn.startCollect(ctx);
    doubleColumn.setNextReader(new ReaderContext(readerContext));
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10);
    double d = 0.5;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        doubleColumn.setNextDocId(doc.doc);
        assertThat(doubleColumn.value(), is(d));
        d++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) DoubleColumnReference(io.crate.expression.reference.doc.lucene.DoubleColumnReference) 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