Skip to content

Commit

Permalink
fixed bulk delete for partitioned tables
Browse files Browse the repository at this point in the history
where partition column was part of the where clause
  • Loading branch information
chaudum committed Jul 2, 2015
1 parent 1ee87b3 commit 4b264ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changes for Crate
Unreleased
==========

- Fixed bulk delete for partitioned tables where partition column was part
of the where clause

- Fixed a possible race condition which leads to the execution of a
non-distributed group by instead of a distributed one.

Expand Down
2 changes: 1 addition & 1 deletion sql/src/main/java/io/crate/planner/Planner.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private void createESDeleteByQueryNode(TableInfo tableInfo,

List<String[]> indicesList = new ArrayList<>(whereClauses.size());
for (WhereClause whereClause : whereClauses) {
String[] indices = indices(tableInfo, whereClauses.get(0));
String[] indices = indices(tableInfo, whereClause);
if (indices.length > 0) {
if (!whereClause.hasQuery() && tableInfo.isPartitioned()) {
plan.add(new ESDeletePartitionNode(indices));
Expand Down
1 change: 0 additions & 1 deletion sql/src/test/java/io/crate/analyze/DeleteAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public void testDeleteWherePartitionedByColumn() throws Exception {
assertThat(statement.whereClauses().get(0).partitions().size(), is(1));
assertThat(statement.whereClauses().get(0).partitions().get(0),
is(".partitioned.parted.04732cpp6ks3ed1o60o30c1g"));

}

@Test
Expand Down
25 changes: 25 additions & 0 deletions sql/src/test/java/io/crate/planner/PlannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.crate.planner.node.PlanNode;
import io.crate.planner.node.ddl.DropTableNode;
import io.crate.planner.node.ddl.ESClusterUpdateSettingsNode;
import io.crate.planner.node.ddl.ESDeletePartitionNode;
import io.crate.planner.node.dml.*;
import io.crate.planner.node.dql.*;
import io.crate.planner.node.management.KillPlan;
Expand Down Expand Up @@ -284,6 +285,16 @@ private Plan plan(String statement) {
new ParameterContext(new Object[0], new Object[0][], ReferenceInfos.DEFAULT_SCHEMA_NAME)), UUID.randomUUID());
}

private Plan plan(String statement, Object[] args) {
return planner.plan(analyzer.analyze(SqlParser.createStatement(statement),
new ParameterContext(args, new Object[0][], ReferenceInfos.DEFAULT_SCHEMA_NAME)), UUID.randomUUID());
}

private Plan plan(String statement, Object[][] bulkArgs) {
return planner.plan(analyzer.analyze(SqlParser.createStatement(statement),
new ParameterContext(new Object[0], bulkArgs, ReferenceInfos.DEFAULT_SCHEMA_NAME)), UUID.randomUUID());
}

@Test
public void testGroupByWithAggregationStringLiteralArguments() {
CollectPhase collectNode = ((DistributedGroupBy) plan("select count('foo'), name from users group by name")).collectNode();
Expand Down Expand Up @@ -407,6 +418,20 @@ public void testDeletePlan() throws Exception {
assertFalse(iterator.hasNext());
}

@Test
public void testBulkDeletePartitionedTable() throws Exception {
IterablePlan plan = (IterablePlan) plan("delete from parted where date = ?", new Object[][]{
new Object[]{"0"},
new Object[]{"123"},
});
Iterator<PlanNode> iterator = plan.iterator();
ESDeletePartitionNode node1 = (ESDeletePartitionNode) iterator.next();
assertThat(node1.indices(), is(new String[]{".partitioned.parted.04130"}));
ESDeletePartitionNode node2 = (ESDeletePartitionNode) iterator.next();
assertThat(node2.indices(), is(new String[]{ ".partitioned.parted.04232chj" }));
assertFalse(iterator.hasNext());
}

@Test
public void testMultiDeletePlan() throws Exception {
IterablePlan plan = (IterablePlan) plan("delete from users where id in (1, 2)");
Expand Down

0 comments on commit 4b264ba

Please sign in to comment.