use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testOrderByOnAlias.
@Test
public void testOrderByOnAlias() throws Exception {
QueriedRelation relation = analyze("select name as cluster_name from sys.cluster order by cluster_name").relation();
List<String> outputNames = outputNames(relation);
assertThat(outputNames.size(), is(1));
assertThat(outputNames.get(0), is("cluster_name"));
assertTrue(relation.querySpec().orderBy().isPresent());
assertThat(relation.querySpec().orderBy().get().orderBySymbols().size(), is(1));
assertThat(relation.querySpec().orderBy().get().orderBySymbols().get(0), is(relation.querySpec().outputs().get(0)));
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testGroupByOnAlias.
@Test
public void testGroupByOnAlias() throws Exception {
QueriedRelation relation = analyze("select count(*), name as n from sys.nodes group by n").relation();
assertThat(relation.querySpec().groupBy().get().size(), is(1));
assertThat(relation.fields().get(0).path().outputName(), is("count(*)"));
assertThat(relation.fields().get(1).path().outputName(), is("n"));
assertEquals(relation.querySpec().groupBy().get().get(0), relation.querySpec().outputs().get(1));
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testWhereSelect.
@Test
public void testWhereSelect() throws Exception {
QueriedRelation relation = analyze("select load from sys.nodes " + "where load['1'] = 1.2 or 1 >= load['5']").relation();
assertFalse(relation.querySpec().groupBy().isPresent());
Function whereClause = (Function) relation.querySpec().where().query();
assertEquals(OrOperator.NAME, whereClause.info().ident().name());
assertFalse(whereClause.info().type() == FunctionInfo.Type.AGGREGATE);
Function left = (Function) whereClause.arguments().get(0);
assertEquals(EqOperator.NAME, left.info().ident().name());
assertThat(left.arguments().get(0), isReference("load['1']"));
assertThat(left.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
assertSame(left.arguments().get(1).valueType(), DataTypes.DOUBLE);
Function right = (Function) whereClause.arguments().get(1);
assertEquals(LteOperator.NAME, right.info().ident().name());
assertThat(right.arguments().get(0), isReference("load['5']"));
assertThat(right.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
assertSame(left.arguments().get(1).valueType(), DataTypes.DOUBLE);
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SelectStatementAnalyzerTest method testRewriteNotEquals.
@Test
public void testRewriteNotEquals() {
// should rewrite to:
// not(eq(sys.noes.name, 'something'))
ImmutableList<String> statements = ImmutableList.of("select * from sys.nodes where sys.nodes.name <> 'something'", "select * from sys.nodes where sys.nodes.name != 'something'");
for (String statement : statements) {
QueriedRelation relation = analyze(statement).relation();
WhereClause whereClause = relation.querySpec().where();
Function notFunction = (Function) whereClause.query();
assertThat(notFunction.info().ident().name(), is(NotPredicate.NAME));
assertThat(notFunction.arguments().size(), is(1));
Function eqFunction = (Function) notFunction.arguments().get(0);
assertThat(eqFunction.info().ident().name(), is(EqOperator.NAME));
assertThat(eqFunction.arguments().size(), is(2));
List<Symbol> eqArguments = eqFunction.arguments();
assertThat(eqArguments.get(1), isLiteral("something"));
}
}
use of io.crate.analyze.relations.QueriedRelation in project crate by crate.
the class SubqueryPlanner method planSubquery.
private void planSubquery(SelectSymbol selectSymbol) {
AnalyzedRelation relation = selectSymbol.relation();
SelectAnalyzedStatement selectAnalyzedStatement = new SelectAnalyzedStatement(((QueriedRelation) relation));
Plan subPlan = plannerContext.planSingleRowSubselect(selectAnalyzedStatement);
subQueries.put(subPlan, selectSymbol);
}
Aggregations