Search in sources :

Example 1 with ESDeletePartition

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));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Bucket(io.crate.data.Bucket) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BytesRef(org.apache.lucene.util.BytesRef) ESDeletePartition(io.crate.planner.node.ddl.ESDeletePartition) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 2 with ESDeletePartition

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));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Bucket(io.crate.data.Bucket) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BytesRef(org.apache.lucene.util.BytesRef) ESDeletePartition(io.crate.planner.node.ddl.ESDeletePartition) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 3 with ESDeletePartition

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

ESDeletePartition (io.crate.planner.node.ddl.ESDeletePartition)3 Bucket (io.crate.data.Bucket)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 PartitionName (io.crate.metadata.PartitionName)2 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)2 BytesRef (org.apache.lucene.util.BytesRef)2 Test (org.junit.Test)2 WhereClause (io.crate.analyze.WhereClause)1 NoopPlan (io.crate.planner.NoopPlan)1 Plan (io.crate.planner.Plan)1 Delete (io.crate.planner.node.dml.Delete)1 ESDelete (io.crate.planner.node.dml.ESDelete)1