use of io.crate.planner.node.ddl.ESDeletePartition in project crate by crate.
the class TransportExecutorDDLTest method testDeletePartitionTask.
@Test
public void testDeletePartitionTask() throws Exception {
execute("create table t (id integer primary key, name string) partitioned by (id)");
ensureYellow();
execute("insert into t (id, name) values (1, 'Ford')");
assertThat(response.rowCount(), is(1L));
ensureYellow();
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(1L));
String partitionName = new PartitionName("t", ImmutableList.of(new BytesRef("1"))).asIndexName();
ESDeletePartition plan = new ESDeletePartition(UUID.randomUUID(), partitionName);
TestingBatchConsumer consumer = new TestingBatchConsumer();
executor.execute(plan, consumer, Row.EMPTY);
Bucket objects = consumer.getBucket();
assertThat(objects, contains(isRow(-1L)));
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(0L));
}
use of io.crate.planner.node.ddl.ESDeletePartition in project crate by crate.
the class TransportExecutorDDLTest method testDeletePartitionTaskClosed.
/**
* this case should not happen as closed indices aren't listed as TableInfo
* but if it does maybe because of stale cluster state - validate behaviour here
* <p>
* cannot prevent this task from deleting closed indices.
*/
@Test
public void testDeletePartitionTaskClosed() throws Exception {
execute("create table t (id integer primary key, name string) partitioned by (id)");
ensureYellow();
execute("insert into t (id, name) values (1, 'Ford')");
assertThat(response.rowCount(), is(1L));
ensureYellow();
String partitionName = new PartitionName("t", ImmutableList.of(new BytesRef("1"))).asIndexName();
assertTrue(client().admin().indices().prepareClose(partitionName).execute().actionGet().isAcknowledged());
ESDeletePartition plan = new ESDeletePartition(UUID.randomUUID(), partitionName);
TestingBatchConsumer consumer = new TestingBatchConsumer();
executor.execute(plan, consumer, Row.EMPTY);
Bucket bucket = consumer.getBucket();
assertThat(bucket, contains(isRow(-1L)));
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(0L));
}
use of io.crate.planner.node.ddl.ESDeletePartition 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