Search in sources :

Example 1 with NoopPlan

use of io.crate.planner.NoopPlan in project crate by crate.

the class DeleteStatementPlanner method deleteByQuery.

private static Plan deleteByQuery(DocTableInfo tableInfo, List<WhereClause> whereClauses, Planner.Context context) {
    List<Plan> planNodes = new ArrayList<>();
    List<String> indicesToDelete = new ArrayList<>();
    for (WhereClause whereClause : whereClauses) {
        String[] indices = Planner.indices(tableInfo, whereClause);
        if (indices.length > 0) {
            if (!whereClause.hasQuery() && tableInfo.isPartitioned()) {
                indicesToDelete.addAll(Arrays.asList(indices));
            } else {
                planNodes.add(collectWithDeleteProjection(tableInfo, whereClause, context));
            }
        }
    }
    if (!indicesToDelete.isEmpty()) {
        assert planNodes.isEmpty() : "If a partition can be deleted that must be true for all bulk operations";
        return new ESDeletePartition(context.jobId(), indicesToDelete.toArray(new String[0]));
    }
    if (planNodes.isEmpty()) {
        return new NoopPlan(context.jobId());
    }
    return new Delete(planNodes, context.jobId());
}
Also used : ESDelete(io.crate.planner.node.dml.ESDelete) Delete(io.crate.planner.node.dml.Delete) NoopPlan(io.crate.planner.NoopPlan) WhereClause(io.crate.analyze.WhereClause) Plan(io.crate.planner.Plan) NoopPlan(io.crate.planner.NoopPlan) ESDeletePartition(io.crate.planner.node.ddl.ESDeletePartition)

Example 2 with NoopPlan

use of io.crate.planner.NoopPlan in project crate by crate.

the class ESGetStatementPlanner method convert.

public static Plan convert(QueriedDocTable table, Planner.Context context) {
    QuerySpec querySpec = table.querySpec();
    Optional<DocKeys> optKeys = querySpec.where().docKeys();
    assert !querySpec.hasAggregates() : "Can't create ESGet plan for queries with aggregates";
    assert !querySpec.groupBy().isPresent() : "Can't create ESGet plan for queries with group by";
    assert optKeys.isPresent() : "Can't create ESGet without docKeys";
    DocTableInfo tableInfo = table.tableRelation().tableInfo();
    DocKeys docKeys = optKeys.get();
    if (docKeys.withVersions()) {
        throw new VersionInvalidException();
    }
    Limits limits = context.getLimits(querySpec);
    if (limits.hasLimit() && limits.finalLimit() == 0) {
        return new NoopPlan(context.jobId());
    }
    table.tableRelation().validateOrderBy(querySpec.orderBy());
    return new ESGet(context.nextExecutionPhaseId(), tableInfo, querySpec.outputs(), optKeys.get(), querySpec.orderBy(), limits.finalLimit(), limits.offset(), context.jobId());
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) NoopPlan(io.crate.planner.NoopPlan) Limits(io.crate.planner.Limits) DocKeys(io.crate.analyze.where.DocKeys) ESGet(io.crate.planner.node.dql.ESGet) QuerySpec(io.crate.analyze.QuerySpec) VersionInvalidException(io.crate.exceptions.VersionInvalidException)

Example 3 with NoopPlan

use of io.crate.planner.NoopPlan in project crate by crate.

the class DeleteStatementPlanner method planDelete.

public static Plan planDelete(DeleteAnalyzedStatement analyzedStatement, Planner.Context context) {
    DocTableRelation tableRelation = analyzedStatement.analyzedRelation();
    List<WhereClause> whereClauses = new ArrayList<>(analyzedStatement.whereClauses().size());
    List<DocKeys.DocKey> docKeys = new ArrayList<>(analyzedStatement.whereClauses().size());
    Map<Integer, Integer> itemToBulkIdx = new HashMap<>();
    int bulkIdx = -1;
    int itemIdx = 0;
    for (WhereClause whereClause : analyzedStatement.whereClauses()) {
        bulkIdx++;
        if (whereClause.noMatch()) {
            continue;
        }
        if (whereClause.docKeys().isPresent() && whereClause.docKeys().get().size() == 1) {
            DocKeys.DocKey docKey = whereClause.docKeys().get().getOnlyKey();
            if (docKey.id() != null) {
                docKeys.add(docKey);
                itemToBulkIdx.put(itemIdx, bulkIdx);
                itemIdx++;
            }
        } else if (!whereClause.noMatch()) {
            whereClauses.add(whereClause);
        }
    }
    if (!docKeys.isEmpty()) {
        return new ESDelete(context.jobId(), context.nextExecutionPhaseId(), tableRelation.tableInfo(), docKeys, itemToBulkIdx, analyzedStatement.whereClauses().size());
    } else if (!whereClauses.isEmpty()) {
        return deleteByQuery(tableRelation.tableInfo(), whereClauses, context);
    }
    return new NoopPlan(context.jobId());
}
Also used : NoopPlan(io.crate.planner.NoopPlan) DocKeys(io.crate.analyze.where.DocKeys) WhereClause(io.crate.analyze.WhereClause) ESDelete(io.crate.planner.node.dml.ESDelete) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Aggregations

NoopPlan (io.crate.planner.NoopPlan)3 WhereClause (io.crate.analyze.WhereClause)2 DocKeys (io.crate.analyze.where.DocKeys)2 ESDelete (io.crate.planner.node.dml.ESDelete)2 QuerySpec (io.crate.analyze.QuerySpec)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 VersionInvalidException (io.crate.exceptions.VersionInvalidException)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 Limits (io.crate.planner.Limits)1 Plan (io.crate.planner.Plan)1 ESDeletePartition (io.crate.planner.node.ddl.ESDeletePartition)1 Delete (io.crate.planner.node.dml.Delete)1 ESGet (io.crate.planner.node.dql.ESGet)1