Search in sources :

Example 6 with AnalyzedRelation

use of io.crate.analyze.relations.AnalyzedRelation in project crate by crate.

the class SimplePortal method bind.

@Override
public Portal bind(String statementName, String query, Statement statement, List<Object> params, @Nullable FormatCodes.FormatCode[] resultFormatCodes) {
    if (statement.equals(this.statement)) {
        if (portalContext.isReadOnly()) {
            // Cannot have a bulk operation in read only mode
            throw new ReadOnlyException();
        }
        assert consumer == null : "Existing portal must not have a consumer";
        BulkPortal portal = new BulkPortal(name, this.query, this.statement, outputTypes, fields(), resultReceiver, maxRows, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    } else if (this.statement != null) {
        assert consumer == null : "Existing portal must not have a consumer";
        if (portalContext.isReadOnly()) {
            // Cannot have a batch operation in read only mode
            throw new ReadOnlyException();
        }
        BatchPortal portal = new BatchPortal(name, this.query, analysis, outputTypes, resultReceiver, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    }
    this.query = query;
    this.statement = statement;
    this.params = params;
    this.rowParams = new RowN(params.toArray());
    this.resultFormatCodes = resultFormatCodes;
    if (analysis == null) {
        analysis = portalContext.getAnalyzer().boundAnalyze(statement, sessionContext, new ParameterContext(this.rowParams, Collections.<Row>emptyList()));
        AnalyzedRelation rootRelation = analysis.rootRelation();
        if (rootRelation != null) {
            this.outputTypes = new ArrayList<>(Symbols.extractTypes(rootRelation.fields()));
        }
    }
    return this;
}
Also used : RowN(io.crate.data.RowN) ParameterContext(io.crate.analyze.ParameterContext) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ReadOnlyException(io.crate.exceptions.ReadOnlyException)

Example 7 with AnalyzedRelation

use of io.crate.analyze.relations.AnalyzedRelation 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);
}
Also used : QueriedRelation(io.crate.analyze.relations.QueriedRelation) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SelectAnalyzedStatement(io.crate.analyze.SelectAnalyzedStatement)

Example 8 with AnalyzedRelation

use of io.crate.analyze.relations.AnalyzedRelation in project crate by crate.

the class InternalCountOperationTest method testCount.

@Test
public void testCount() throws Exception {
    execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
    execute("refresh table t");
    CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
    assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
    assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
Also used : QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) TableInfo(io.crate.metadata.table.TableInfo) TableIdent(io.crate.metadata.TableIdent) Schemas(io.crate.metadata.Schemas) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Aggregations

AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)8 TableRelation (io.crate.analyze.relations.TableRelation)5 QualifiedName (io.crate.sql.tree.QualifiedName)5 SqlExpressions (io.crate.testing.SqlExpressions)5 WhereClause (io.crate.analyze.WhereClause)3 Test (org.junit.Test)3 TableIdent (io.crate.metadata.TableIdent)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 TableInfo (io.crate.metadata.table.TableInfo)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 Before (org.junit.Before)2 ParameterContext (io.crate.analyze.ParameterContext)1 SelectAnalyzedStatement (io.crate.analyze.SelectAnalyzedStatement)1 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)1 FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)1 QueriedRelation (io.crate.analyze.relations.QueriedRelation)1 Field (io.crate.analyze.symbol.Field)1 Function (io.crate.analyze.symbol.Function)1 RowN (io.crate.data.RowN)1 ReadOnlyException (io.crate.exceptions.ReadOnlyException)1