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);
}
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);
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class WindowAgg method create.
@VisibleForTesting
public static LogicalPlan create(LogicalPlan source, List<WindowFunction> windowFunctions) {
if (windowFunctions.isEmpty()) {
return source;
}
LinkedHashMap<WindowDefinition, ArrayList<WindowFunction>> groupedFunctions = new LinkedHashMap<>();
for (WindowFunction windowFunction : windowFunctions) {
WindowDefinition windowDefinition = windowFunction.windowDefinition();
ArrayList<WindowFunction> functions = groupedFunctions.computeIfAbsent(windowDefinition, w -> new ArrayList<>());
functions.add(windowFunction);
}
LogicalPlan lastWindowAgg = source;
for (Map.Entry<WindowDefinition, ArrayList<WindowFunction>> entry : groupedFunctions.entrySet()) {
/*
* Pass along the source outputs as standalone symbols as they might be required in cases like:
* select x, avg(x) OVER() from t;
*/
ArrayList<WindowFunction> functions = entry.getValue();
WindowDefinition windowDefinition = entry.getKey();
OrderBy orderBy = windowDefinition.orderBy();
if (orderBy == null || lastWindowAgg.outputs().containsAll(orderBy.orderBySymbols())) {
lastWindowAgg = new WindowAgg(lastWindowAgg, windowDefinition, functions, lastWindowAgg.outputs());
} else {
// ``WindowProjector.createUpdateProbeValueFunction` expects that all OrderBY symbols are `InputColumn`
// Here we have a case where there is a function or something in the orderBy expression that is *not*
// already provided by the source.
// -> Inject `eval` so that the `orderBy` of the window-function will turn into a `InputColumn`
Eval eval = new Eval(lastWindowAgg, Lists2.concatUnique(lastWindowAgg.outputs(), orderBy.orderBySymbols()));
lastWindowAgg = new WindowAgg(eval, windowDefinition, functions, eval.outputs());
}
}
return lastWindowAgg;
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class NodeStatsTest method testNodeStatsIteratorContrat.
@Test
public void testNodeStatsIteratorContrat() throws Exception {
List<Symbol> toCollect = new ArrayList<>();
toCollect.add(idRef);
when(collectPhase.toCollect()).thenReturn(toCollect);
when(collectPhase.where()).thenReturn(Literal.BOOLEAN_TRUE);
when(collectPhase.orderBy()).thenReturn(new OrderBy(Collections.singletonList(idRef)));
List<Object[]> expectedResult = Arrays.asList(new Object[] { "nodeOne" }, new Object[] { "nodeTwo" });
BatchIteratorTester tester = new BatchIteratorTester(() -> NodeStats.newInstance(transportNodeStatsAction, collectPhase, nodes, txnCtx, new InputFactory(nodeCtx)));
tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class LuceneOrderedDocCollectorTest method testSearchAfterWithSystemColumn.
@Test
public void testSearchAfterWithSystemColumn() {
Reference sysColReference = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "table"), DocSysColumns.SCORE), RowGranularity.DOC, DataTypes.FLOAT, 0, null);
OrderBy orderBy = new OrderBy(List.of(sysColReference, REFERENCE), new boolean[] { false, false }, new boolean[] { false, false });
FieldDoc lastCollected = new FieldDoc(0, 0, new Object[] { 2L });
OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType);
Query nextPageQuery = queryForSearchAfter.apply(lastCollected);
// returns null which leads to reuse of old query without paging optimization
assertNull(nextPageQuery);
}
Aggregations