use of io.crate.analyze.OrderBy in project crate by crate.
the class QueriedDocTableFetchPushDownTest method testPushDownOrderRefUsedInFunction.
@Test
public void testPushDownOrderRefUsedInFunction() throws Exception {
QuerySpec qs = new QuerySpec();
Function funcOfI = abs(REF_I);
qs.outputs(Lists.newArrayList(REF_A, REF_I, funcOfI));
qs.orderBy(new OrderBy(Lists.newArrayList(REF_I), new boolean[] { true }, new Boolean[] { false }));
QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
QueriedDocTable sub = pd.pushDown();
assertThat(qs, isSQL("SELECT FETCH(INPUT(0), s.t._doc['a']), INPUT(1), abs(INPUT(1)) ORDER BY INPUT(1) DESC NULLS LAST"));
assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, s.t.i ORDER BY s.t.i DESC NULLS LAST"));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class QueriedDocTableFetchPushDownTest method testPushDownWithNestedOrder.
@Test
public void testPushDownWithNestedOrder() throws Exception {
QuerySpec qs = new QuerySpec();
qs.outputs(Lists.newArrayList(REF_A, REF_I));
qs.orderBy(new OrderBy(Lists.newArrayList(abs(REF_I)), new boolean[] { true }, new Boolean[] { false }));
QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
QueriedDocTable sub = pd.pushDown();
assertThat(qs, isSQL("SELECT FETCH(INPUT(0), s.t._doc['a']), FETCH(INPUT(0), s.t._doc['i']) ORDER BY INPUT(1) DESC NULLS LAST"));
assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, abs(s.t.i) ORDER BY abs(s.t.i) DESC NULLS LAST"));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class QueriedDocTableFetchPushDownTest method testPushDownWithNestedOrderInOutput.
@Test
public void testPushDownWithNestedOrderInOutput() throws Exception {
QuerySpec qs = new QuerySpec();
Function funcOfI = abs(REF_I);
qs.outputs(Lists.newArrayList(REF_A, REF_I, funcOfI));
qs.orderBy(new OrderBy(Lists.newArrayList(funcOfI), new boolean[] { true }, new Boolean[] { false }));
QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
QueriedDocTable sub = pd.pushDown();
assertThat(qs, isSQL("SELECT FETCH(INPUT(0), s.t._doc['a']), FETCH(INPUT(0), s.t._doc['i']), INPUT(1) ORDER BY INPUT(1) DESC NULLS LAST"));
assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, abs(s.t.i) ORDER BY abs(s.t.i) DESC NULLS LAST"));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class SystemCollectSourceTest method testOrderBySymbolsDoNotAppearTwiceInRows.
@Test
public void testOrderBySymbolsDoNotAppearTwiceInRows() throws Exception {
SystemCollectSource systemCollectSource = internalCluster().getInstance(SystemCollectSource.class);
Reference shardId = new Reference(new ReferenceIdent(new TableIdent("sys", "shards"), "id"), RowGranularity.SHARD, DataTypes.INTEGER);
RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(ImmutableMap.of()), RowGranularity.SHARD, Collections.singletonList(shardId), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
collectPhase.orderBy(new OrderBy(Collections.singletonList(shardId), new boolean[] { false }, new Boolean[] { null }));
Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, false).apply(Collections.singletonList(new UnassignedShard(new ShardId("foo", 1), mock(ClusterService.class), true, ShardRoutingState.UNASSIGNED)));
Row next = rows.iterator().next();
assertThat(next.numColumns(), is(1));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class LuceneOrderedDocCollectorTest method nextPageQuery.
private Long[] nextPageQuery(IndexReader reader, FieldDoc lastCollected, boolean reverseFlag, @Nullable Boolean nullFirst) throws IOException {
OrderBy orderBy = new OrderBy(ImmutableList.<Symbol>of(REFERENCE), new boolean[] { reverseFlag }, new Boolean[] { nullFirst });
SortField sortField = new SortedNumericSortField("value", SortField.Type.LONG, reverseFlag);
Long missingValue = (Long) LuceneMissingValue.missingValue(orderBy, 0);
sortField.setMissingValue(missingValue);
Sort sort = new Sort(sortField);
Query nextPageQuery = LuceneOrderedDocCollector.nextPageQuery(lastCollected, orderBy, new Object[] { missingValue }, name -> valueFieldType);
TopFieldDocs result = search(reader, nextPageQuery, sort);
Long[] results = new Long[result.scoreDocs.length];
for (int i = 0; i < result.scoreDocs.length; i++) {
Long value = (Long) ((FieldDoc) result.scoreDocs[i]).fields[0];
results[i] = value.equals(missingValue) ? null : value;
}
return results;
}
Aggregations