Search in sources :

Example 1 with RelationsUnknown

use of io.crate.exceptions.RelationsUnknown in project crate by crate.

the class ViewAnalyzer method analyze.

public AnalyzedDropView analyze(DropView dropView, CoordinatorTxnCtx txnCtx) {
    // No exists check to avoid stale clusterState race conditions
    ArrayList<RelationName> views = new ArrayList<>(dropView.names().size());
    ArrayList<RelationName> missing = new ArrayList<>();
    for (QualifiedName qualifiedName : dropView.names()) {
        try {
            views.add(schemas.resolveView(qualifiedName, txnCtx.sessionContext().searchPath()).v2());
        } catch (RelationUnknown e) {
            if (!dropView.ifExists()) {
                missing.add(RelationName.of(qualifiedName, txnCtx.sessionContext().searchPath().currentSchema()));
            }
        }
    }
    if (!missing.isEmpty()) {
        throw new RelationsUnknown(missing);
    }
    return new AnalyzedDropView(views, dropView.ifExists());
}
Also used : RelationsUnknown(io.crate.exceptions.RelationsUnknown) RelationUnknown(io.crate.exceptions.RelationUnknown) QualifiedName(io.crate.sql.tree.QualifiedName) ArrayList(java.util.ArrayList) RelationName(io.crate.metadata.RelationName)

Example 2 with RelationsUnknown

use of io.crate.exceptions.RelationsUnknown in project crate by crate.

the class DropViewPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    DropViewRequest request = new DropViewRequest(dropView.views(), dropView.ifExists());
    Function<DropViewResponse, Row> responseToRow = resp -> {
        if (dropView.ifExists() || resp.missing().isEmpty()) {
            return new Row1((long) dropView.views().size() - resp.missing().size());
        }
        throw new RelationsUnknown(resp.missing());
    };
    dependencies.dropViewAction().execute(request, new OneRowActionListener<>(consumer, responseToRow));
}
Also used : RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) RelationsUnknown(io.crate.exceptions.RelationsUnknown) SubQueryResults(io.crate.planner.operators.SubQueryResults) DropViewRequest(io.crate.execution.ddl.views.DropViewRequest) DropViewResponse(io.crate.execution.ddl.views.DropViewResponse) AnalyzedDropView(io.crate.analyze.AnalyzedDropView) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Function(java.util.function.Function) Row1(io.crate.data.Row1) DropViewRequest(io.crate.execution.ddl.views.DropViewRequest) Row1(io.crate.data.Row1) DropViewResponse(io.crate.execution.ddl.views.DropViewResponse) RelationsUnknown(io.crate.exceptions.RelationsUnknown) Row(io.crate.data.Row)

Aggregations

RelationsUnknown (io.crate.exceptions.RelationsUnknown)2 AnalyzedDropView (io.crate.analyze.AnalyzedDropView)1 Row (io.crate.data.Row)1 Row1 (io.crate.data.Row1)1 RowConsumer (io.crate.data.RowConsumer)1 RelationUnknown (io.crate.exceptions.RelationUnknown)1 DropViewRequest (io.crate.execution.ddl.views.DropViewRequest)1 DropViewResponse (io.crate.execution.ddl.views.DropViewResponse)1 OneRowActionListener (io.crate.execution.support.OneRowActionListener)1 RelationName (io.crate.metadata.RelationName)1 SubQueryResults (io.crate.planner.operators.SubQueryResults)1 QualifiedName (io.crate.sql.tree.QualifiedName)1 ArrayList (java.util.ArrayList)1 Function (java.util.function.Function)1