use of io.crate.analyze.QuerySpec in project crate by crate.
the class MultiSourceAggregationConsumer method removeAggregationsAndLimitsFromMSS.
private static void removeAggregationsAndLimitsFromMSS(MultiSourceSelect mss, SplitPoints splitPoints) {
QuerySpec querySpec = mss.querySpec();
List<Symbol> outputs = Lists2.concatUnique(splitPoints.toCollect(), extractFieldsFromJoinConditions(mss));
querySpec.outputs(outputs);
querySpec.hasAggregates(false);
// Limit & offset must be applied after the aggregation, so remove it from mss and sources.
// OrderBy can be ignored because it's also applied after aggregation but there is always only 1 row so it
// wouldn't have any effect.
removeLimitOffsetAndOrder(querySpec);
for (RelationSource relationSource : mss.sources().values()) {
removeLimitOffsetAndOrder(relationSource.querySpec());
}
// need to change the types on the fields of the MSS to match the new outputs
ListIterator<Field> fieldsIt = mss.fields().listIterator();
Iterator<Function> outputsIt = splitPoints.aggregates().iterator();
while (fieldsIt.hasNext()) {
Field field = fieldsIt.next();
Symbol output = outputsIt.next();
fieldsIt.set(new Field(field.relation(), field.path(), output.valueType()));
}
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class RelationSplitterTest method testQuerySpecSplit.
@Test
public void testQuerySpecSplit() throws Exception {
QuerySpec querySpec = fromQuery("x = 1 and y = 3 and x + y = 4");
RelationSplitter splitter = split(querySpec);
assertThat(querySpec, isSQL("SELECT true WHERE (true AND (add(doc.t1.x, doc.t2.y) = 4))"));
assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x WHERE (doc.t1.x = 1)"));
assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y WHERE (true AND (doc.t2.y = 3))"));
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class QueriedDocTableFetchPushDownTest method testScoreGetsPushedDown.
@Test
public void testScoreGetsPushedDown() throws Exception {
QuerySpec qs = new QuerySpec();
qs.outputs(Lists.newArrayList(REF_A, REF_I, REF_SCORE));
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), INPUT(2) ORDER BY INPUT(1) DESC NULLS LAST"));
assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, s.t.i, s.t._score ORDER BY s.t.i DESC NULLS LAST"));
}
use of io.crate.analyze.QuerySpec 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.QuerySpec 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"));
}
Aggregations