Search in sources :

Example 1 with IpColumnReference

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

the class IpColumnReferenceTest method testNullDocValuesDoNotResultInNPE.

@Test
public void testNullDocValuesDoNotResultInNPE() throws IOException {
    IpColumnReference ref = new IpColumnReference("missing_column");
    ref.startCollect(ctx);
    ref.setNextReader(new ReaderContext(readerContext));
    ref.setNextDocId(0);
    assertThat(ref.value(), Matchers.nullValue());
}
Also used : IpColumnReference(io.crate.expression.reference.doc.lucene.IpColumnReference) ReaderContext(io.crate.execution.engine.fetch.ReaderContext) Test(org.junit.Test)

Example 2 with IpColumnReference

use of io.crate.expression.reference.doc.lucene.IpColumnReference 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 3 with IpColumnReference

use of io.crate.expression.reference.doc.lucene.IpColumnReference 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)3 IpColumnReference (io.crate.expression.reference.doc.lucene.IpColumnReference)3 Test (org.junit.Test)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 TopDocs (org.apache.lucene.search.TopDocs)2 InetAddressPoint (org.apache.lucene.document.InetAddressPoint)1