use of io.crate.analyze.QuerySpec in project crate by crate.
the class RelationSplitterTest method testNoSplitOnOuterJoinRelation.
@Test
public void testNoSplitOnOuterJoinRelation() throws Exception {
QuerySpec querySpec = fromQuery("t2.y < 10");
JoinPair joinPair = new JoinPair(T3.T1, T3.T2, JoinType.LEFT, asSymbol("t1.a = t2.b"));
RelationSplitter splitter = split(querySpec, Arrays.asList(joinPair));
assertThat(querySpec, isSQL("SELECT true WHERE (doc.t2.y < 10)"));
assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.a"));
assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y, doc.t2.b"));
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class RelationSplitterTest method testSplitOrderByThatIsPartiallyConsumed.
@Test
public void testSplitOrderByThatIsPartiallyConsumed() throws Exception {
// select a from t1, t2 order by a, b + x desc
List<Symbol> orderBySymbols = Arrays.asList(asSymbol("a"), asSymbol("x + y"));
OrderBy orderBy = new OrderBy(orderBySymbols, new boolean[] { true, false }, new Boolean[] { null, null });
QuerySpec querySpec = new QuerySpec().outputs(singleTrue()).orderBy(orderBy);
RelationSplitter splitter = split(querySpec);
assertThat(querySpec, isSQL("SELECT true ORDER BY doc.t1.a DESC, add(doc.t1.x, doc.t2.y)"));
assertThat(splitter.remainingOrderBy().isPresent(), is(true));
assertThat(splitter.remainingOrderBy().get().orderBy(), isSQL("doc.t1.a DESC, add(doc.t1.x, doc.t2.y)"));
assertThat(splitter.requiredForQuery(), isSQL("doc.t1.a, doc.t1.x, doc.t2.y, add(doc.t1.x, doc.t2.y)"));
assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.a, doc.t1.x"));
assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y"));
assertThat(splitter.canBeFetched(), empty());
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class RelationSplitterTest method testSplitOrderByCombiningColumnsFrom3Relations.
@Test
public void testSplitOrderByCombiningColumnsFrom3Relations() throws Exception {
// select a, b from t1, t2, t3 order by x, x - y + z, y, x + y
QuerySpec querySpec = new QuerySpec().outputs(Arrays.asList(asSymbol("a"), asSymbol("b")));
List<Symbol> orderBySymbols = Arrays.asList(asSymbol("x"), asSymbol("x - y + z"), asSymbol("y"), asSymbol("x+y"));
OrderBy orderBy = new OrderBy(orderBySymbols, new boolean[] { false, false, false, false }, new Boolean[] { null, null, null, null });
querySpec.orderBy(orderBy);
RelationSplitter splitter = split(querySpec);
assertThat(querySpec, isSQL("SELECT doc.t1.a, doc.t2.b " + "ORDER BY doc.t1.x, add(subtract(doc.t1.x, doc.t2.y), doc.t3.z), " + "doc.t2.y, add(doc.t1.x, doc.t2.y)"));
assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x, doc.t1.a"));
assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y, doc.t2.b"));
assertThat(splitter.getSpec(T3.TR_3), isSQL("SELECT doc.t3.z"));
assertThat(splitter.remainingOrderBy().isPresent(), is(true));
assertThat(splitter.remainingOrderBy().get().orderBy(), isSQL("doc.t1.x, add(subtract(doc.t1.x, doc.t2.y), doc.t3.z), doc.t2.y, add(doc.t1.x, doc.t2.y)"));
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class ConsumingPlanner method plan.
@Nullable
public Plan plan(AnalyzedRelation relation, ConsumerContext consumerContext) {
for (Consumer consumer : consumers) {
Plan plan = consumer.consume(relation, consumerContext);
if (plan != null) {
if (relation instanceof QueriedRelation) {
QuerySpec qs = ((QueriedRelation) relation).querySpec();
SubqueryPlanner subqueryPlanner = new SubqueryPlanner(consumerContext.plannerContext());
Map<Plan, SelectSymbol> subQueries = subqueryPlanner.planSubQueries(qs);
return MultiPhasePlan.createIfNeeded(plan, subQueries);
}
return plan;
}
}
ValidationException validationException = consumerContext.validationException();
if (validationException != null) {
throw validationException;
}
return null;
}
use of io.crate.analyze.QuerySpec in project crate by crate.
the class ESGetStatementPlanner method convert.
public static Plan convert(QueriedDocTable table, Planner.Context context) {
QuerySpec querySpec = table.querySpec();
Optional<DocKeys> optKeys = querySpec.where().docKeys();
assert !querySpec.hasAggregates() : "Can't create ESGet plan for queries with aggregates";
assert !querySpec.groupBy().isPresent() : "Can't create ESGet plan for queries with group by";
assert optKeys.isPresent() : "Can't create ESGet without docKeys";
DocTableInfo tableInfo = table.tableRelation().tableInfo();
DocKeys docKeys = optKeys.get();
if (docKeys.withVersions()) {
throw new VersionInvalidException();
}
Limits limits = context.getLimits(querySpec);
if (limits.hasLimit() && limits.finalLimit() == 0) {
return new NoopPlan(context.jobId());
}
table.tableRelation().validateOrderBy(querySpec.orderBy());
return new ESGet(context.nextExecutionPhaseId(), tableInfo, querySpec.outputs(), optKeys.get(), querySpec.orderBy(), limits.finalLimit(), limits.offset(), context.jobId());
}
Aggregations