Search in sources :

Example 26 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class NodeStatsIteratorTest method testNodeStatsIteratorContrat.

@Test
public void testNodeStatsIteratorContrat() throws Exception {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    when(collectPhase.whereClause()).thenReturn(WhereClause.MATCH_ALL);
    when(collectPhase.orderBy()).thenReturn(new OrderBy(Collections.singletonList(idRef), new boolean[] { false }, new Boolean[] { true }));
    List<Object[]> expectedResult = Arrays.asList(new Object[] { new BytesRef("nodeOne") }, new Object[] { new BytesRef("nodeTwo") });
    BatchIteratorTester tester = new BatchIteratorTester(() -> NodeStatsIterator.newInstance(transportNodeStatsAction, collectPhase, nodes, new InputFactory(getFunctions())));
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class OrderedLuceneBatchIteratorFactoryTest method prepareSearchers.

@Before
public void prepareSearchers() throws Exception {
    IndexWriter iw1 = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    IndexWriter iw2 = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    expectedResult = LongStream.range(0, 20).mapToObj(i -> new Object[] { i }).collect(Collectors.toList());
    // expect descending order to differentiate between insert order
    expectedResult.sort(Comparator.comparingLong((Object[] o) -> ((long) o[0])).reversed());
    for (int i = 0; i < 20; i++) {
        Document doc = new Document();
        doc.add(new NumericDocValuesField(columnName, i));
        if (i % 2 == 0) {
            iw1.addDocument(doc);
        } else {
            iw2.addDocument(doc);
        }
    }
    iw1.commit();
    iw2.commit();
    searcher1 = new IndexSearcher(DirectoryReader.open(iw1, true));
    searcher2 = new IndexSearcher(DirectoryReader.open(iw2, true));
    fieldTypeLookup = columnName -> {
        LongFieldMapper.LongFieldType longFieldType = new LongFieldMapper.LongFieldType();
        longFieldType.setNames(new MappedFieldType.Names(columnName));
        return longFieldType;
    };
    orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
Also used : OrderBy(io.crate.analyze.OrderBy) LongFieldMapper(org.elasticsearch.index.mapper.core.LongFieldMapper) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Aggregations

OrderBy (io.crate.analyze.OrderBy)27 Test (org.junit.Test)14 QuerySpec (io.crate.analyze.QuerySpec)13 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)8 Symbol (io.crate.analyze.symbol.Symbol)8 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 InputFactory (io.crate.operation.InputFactory)4 WhereClause (io.crate.analyze.WhereClause)3 Row (io.crate.data.Row)3 Reference (io.crate.metadata.Reference)3 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ShardId (org.elasticsearch.index.shard.ShardId)3 Function (io.crate.analyze.symbol.Function)2 AbsFunction (io.crate.operation.scalar.arithmetic.AbsFunction)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Document (org.apache.lucene.document.Document)2