Search in sources :

Example 1 with BytesRefColumnReference

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

the class DocValuesGroupByOptimizedIteratorTest method test_group_by_doc_values_optimized_iterator_for_many_keys.

@Test
public void test_group_by_doc_values_optimized_iterator_for_many_keys() throws Exception {
    SumAggregation<?> sumAggregation = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.LONG), DataTypes.LONG);
    var sumDocValuesAggregator = sumAggregation.getDocValueAggregator(List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "z"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null)), mock(DocTableInfo.class), List.of());
    var keyExpressions = List.of(new BytesRefColumnReference("x"), new LongColumnReference("y"));
    var keyRefs = List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "x"), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 1, null), new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 2, null));
    var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forManyKeys(List.of(sumDocValuesAggregator), indexSearcher, keyRefs, keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
    var rowConsumer = new TestingRowConsumer();
    rowConsumer.accept(it, null);
    assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { "0", 0L, 6L }, new Object[] { "1", 1L, 4L }));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) Reference(io.crate.metadata.Reference) SumAggregation(io.crate.execution.engine.aggregation.impl.SumAggregation) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ReferenceIdent(io.crate.metadata.ReferenceIdent) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with BytesRefColumnReference

use of io.crate.expression.reference.doc.lucene.BytesRefColumnReference 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)

Aggregations

BytesRefColumnReference (io.crate.expression.reference.doc.lucene.BytesRefColumnReference)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 Test (org.junit.Test)2 SumAggregation (io.crate.execution.engine.aggregation.impl.SumAggregation)1 ReaderContext (io.crate.execution.engine.fetch.ReaderContext)1 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)1 LongColumnReference (io.crate.expression.reference.doc.lucene.LongColumnReference)1 Reference (io.crate.metadata.Reference)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 TestingRowConsumer (io.crate.testing.TestingRowConsumer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TopDocs (org.apache.lucene.search.TopDocs)1