use of io.crate.analyze.relations.QueriedRelation 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.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testSelectWithParameters.
@Test
public void testSelectWithParameters() throws Exception {
QueriedRelation relation = analyze("select load from sys.nodes " + "where load['1'] = ? or load['5'] <= ? or load['15'] >= ? or load['1'] = ? " + "or load['1'] = ? or name = ?", new Object[] { 1.2d, 2.4f, 2L, 3, new Short("1"), "node 1" }).relation();
Function whereClause = (Function) relation.querySpec().where().query();
assertEquals(OrOperator.NAME, whereClause.info().ident().name());
assertFalse(whereClause.info().type() == FunctionInfo.Type.AGGREGATE);
Function function = (Function) whereClause.arguments().get(0);
assertEquals(OrOperator.NAME, function.info().ident().name());
function = (Function) function.arguments().get(1);
assertEquals(EqOperator.NAME, function.info().ident().name());
assertThat(function.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
assertEquals(DataTypes.DOUBLE, function.arguments().get(1).valueType());
function = (Function) whereClause.arguments().get(1);
assertEquals(EqOperator.NAME, function.info().ident().name());
assertThat(function.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
assertEquals(DataTypes.STRING, function.arguments().get(1).valueType());
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testSimpleSelect.
@Test
public void testSimpleSelect() throws Exception {
QueriedRelation relation = analyze("select load['5'] from sys.nodes limit 2").relation();
assertThat(relation.querySpec().limit().get(), is((Symbol) Literal.of(2L)));
assertFalse(relation.querySpec().groupBy().isPresent());
assertEquals(1, relation.querySpec().outputs().size());
assertThat(relation.querySpec().outputs().get(0), isReference("load['5']"));
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testGroupedSelect.
@Test
public void testGroupedSelect() throws Exception {
QueriedRelation relation = analyze("select load['1'], count(*) from sys.nodes group by load['1']").relation();
assertFalse(relation.querySpec().limit().isPresent());
assertNotNull(relation.querySpec().groupBy());
assertEquals(2, relation.querySpec().outputs().size());
assertEquals(1, relation.querySpec().groupBy().get().size());
assertThat(relation.querySpec().groupBy().get().get(0), isReference("load['1']"));
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testAggregationSelect.
@Test
public void testAggregationSelect() throws Exception {
QueriedRelation relation = analyze("select avg(load['5']) from sys.nodes").relation();
assertFalse(relation.querySpec().groupBy().isPresent());
assertEquals(1, relation.querySpec().outputs().size());
Function col1 = (Function) relation.querySpec().outputs().get(0);
assertEquals(FunctionInfo.Type.AGGREGATE, col1.info().type());
assertEquals(AverageAggregation.NAME, col1.info().ident().name());
}
Aggregations