Search in sources :

Example 6 with QueriedRelation

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;
}
Also used : SelectSymbol(io.crate.analyze.symbol.SelectSymbol) ValidationException(io.crate.exceptions.ValidationException) QueriedRelation(io.crate.analyze.relations.QueriedRelation) QuerySpec(io.crate.analyze.QuerySpec) Nullable(javax.annotation.Nullable)

Example 7 with QueriedRelation

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());
}
Also used : DistanceFunction(io.crate.operation.scalar.geo.DistanceFunction) SubscriptFunction(io.crate.operation.scalar.SubscriptFunction) MatchesFunction(io.crate.operation.scalar.regex.MatchesFunction) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with QueriedRelation

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']"));
}
Also used : QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with QueriedRelation

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']"));
}
Also used : QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with QueriedRelation

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());
}
Also used : DistanceFunction(io.crate.operation.scalar.geo.DistanceFunction) SubscriptFunction(io.crate.operation.scalar.SubscriptFunction) MatchesFunction(io.crate.operation.scalar.regex.MatchesFunction) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

QueriedRelation (io.crate.analyze.relations.QueriedRelation)13 CrateUnitTest (io.crate.test.integration.CrateUnitTest)11 Test (org.junit.Test)11 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)5 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)5 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)5 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)5 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)3 QuerySpec (io.crate.analyze.QuerySpec)1 SelectAnalyzedStatement (io.crate.analyze.SelectAnalyzedStatement)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 SelectSymbol (io.crate.analyze.symbol.SelectSymbol)1 ValidationException (io.crate.exceptions.ValidationException)1 Nullable (javax.annotation.Nullable)1