Search in sources :

Example 1 with Delete

use of io.crate.planner.node.dml.Delete in project crate by crate.

the class DeletePlannerTest method testMultiDeletePlan.

@Test
public void testMultiDeletePlan() throws Exception {
    Delete plan = e.plan("delete from users where id in (1, 2)");
    assertThat(plan.nodes().size(), is(1));
    Merge merge = (Merge) plan.nodes().get(0);
    Collect collect = (Collect) merge.subPlan();
    assertThat(collect.collectPhase().projections().size(), is(1));
    assertThat(collect.collectPhase().projections().get(0), instanceOf(DeleteProjection.class));
}
Also used : ESDelete(io.crate.planner.node.dml.ESDelete) Delete(io.crate.planner.node.dml.Delete) Collect(io.crate.planner.node.dql.Collect) DeleteProjection(io.crate.planner.projection.DeleteProjection) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with Delete

use of io.crate.planner.node.dml.Delete 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)

Aggregations

Delete (io.crate.planner.node.dml.Delete)2 ESDelete (io.crate.planner.node.dml.ESDelete)2 WhereClause (io.crate.analyze.WhereClause)1 NoopPlan (io.crate.planner.NoopPlan)1 Plan (io.crate.planner.Plan)1 ESDeletePartition (io.crate.planner.node.ddl.ESDeletePartition)1 Collect (io.crate.planner.node.dql.Collect)1 DeleteProjection (io.crate.planner.projection.DeleteProjection)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 Test (org.junit.Test)1