Search in sources :

Example 1 with CountAggregation

use of io.crate.execution.engine.aggregation.impl.CountAggregation in project crate by crate.

the class GroupByOptimizedIteratorTest method prepare.

@Before
public void prepare() throws Exception {
    NodeContext nodeCtx = createNodeContext();
    IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    columnName = "x";
    expectedResult = new ArrayList<>(20);
    for (long i = 0; i < 20; i++) {
        Document doc = new Document();
        String val = "val_" + i;
        doc.add(new SortedSetDocValuesField(columnName, new BytesRef(val)));
        iw.addDocument(doc);
        expectedResult.add(new Object[] { val, 1L });
    }
    iw.commit();
    indexSearcher = new IndexSearcher(DirectoryReader.open(iw));
    inExpr = new InputCollectExpression(0);
    CountAggregation aggregation = (CountAggregation) nodeCtx.functions().getQualified(CountAggregation.COUNT_STAR_SIGNATURE, Collections.emptyList(), CountAggregation.COUNT_STAR_SIGNATURE.getReturnType().createType());
    aggregationContexts = List.of(new AggregationContext(aggregation, () -> true, List.of()));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AggregationContext(io.crate.execution.engine.aggregation.AggregationContext) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) NodeContext(io.crate.metadata.NodeContext) Document(org.apache.lucene.document.Document) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) CountAggregation(io.crate.execution.engine.aggregation.impl.CountAggregation) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BytesRef(org.apache.lucene.util.BytesRef) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Aggregations

AggregationContext (io.crate.execution.engine.aggregation.AggregationContext)1 CountAggregation (io.crate.execution.engine.aggregation.impl.CountAggregation)1 NodeContext (io.crate.metadata.NodeContext)1 TestingHelpers.createNodeContext (io.crate.testing.TestingHelpers.createNodeContext)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ByteBuffersDirectory (org.apache.lucene.store.ByteBuffersDirectory)1 BytesRef (org.apache.lucene.util.BytesRef)1 Before (org.junit.Before)1