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));
}
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());
}
Aggregations