Skip to content

Commit

Permalink
[Fix](Show-Delete)Missing Delete job information causes query exception
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs committed Jan 18, 2024
1 parent 7ae2b8c commit 996ba96
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
16 changes: 8 additions & 8 deletions fe/fe-core/src/main/java/org/apache/doris/load/DeleteInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ public class DeleteInfo implements Writable, GsonPostProcessable {
@SerializedName(value = "partitionName")
private String partitionName;

public DeleteInfo(long dbId, long tableId, String tableName, List<String> deleteConditions) {
public DeleteInfo(long dbId, long tableId, String tableName, List<String> deleteConditions,
boolean noPartitionSpecified, List<Long> partitionIds, List<String> partitionNames) {
this.dbId = dbId;
this.tableId = tableId;
this.tableName = tableName;
this.deleteConditions = deleteConditions;
this.createTimeMs = System.currentTimeMillis();
this.noPartitionSpecified = noPartitionSpecified;
if (!noPartitionSpecified) {
Preconditions.checkState(partitionIds.size() == partitionNames.size());
this.partitionIds = partitionIds;
this.partitionNames = partitionNames;
}
}

public long getDbId() {
Expand All @@ -92,13 +99,6 @@ public boolean isNoPartitionSpecified() {
return noPartitionSpecified;
}

public void setPartitions(boolean noPartitionSpecified, List<Long> partitionIds, List<String> partitionNames) {
this.noPartitionSpecified = noPartitionSpecified;
Preconditions.checkState(partitionIds.size() == partitionNames.size());
this.partitionIds = partitionIds;
this.partitionNames = partitionNames;
}

public List<Long> getPartitionIds() {
return partitionIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ public List<Predicate> getDeleteConditions() {
public static class Builder {

public DeleteJob buildWith(BuildParams params) throws Exception {
boolean noPartitionSpecified = params.getPartitionNames().isEmpty();
List<Partition> partitions = getSelectedPartitions(params.getTable(),
params.getPartitionNames(), params.getDeleteConditions());
Map<Long, Short> partitionReplicaNum = partitions.stream()
Expand All @@ -504,8 +505,11 @@ public DeleteJob buildWith(BuildParams params) throws Exception {
String label = DELETE_PREFIX + UUID.randomUUID();
//generate jobId
long jobId = Env.getCurrentEnv().getNextId();
List<String> partitionNames = partitions.stream().map(Partition::getName).collect(Collectors.toList());
List<Long> partitionIds = partitions.stream().map(Partition::getId).collect(Collectors.toList());
DeleteInfo deleteInfo = new DeleteInfo(params.getDb().getId(), params.getTable().getId(),
params.getTable().getName(), getDeleteCondString(params.getDeleteConditions()));
params.getTable().getName(), getDeleteCondString(params.getDeleteConditions()),
noPartitionSpecified, partitionIds, partitionNames);
DeleteJob deleteJob = new DeleteJob(jobId, -1, label, partitionReplicaNum, deleteInfo);
long replicaNum = partitions.stream().mapToLong(Partition::getAllReplicaCount).sum();
deleteJob.setPartitions(partitions);
Expand Down
67 changes: 67 additions & 0 deletions regression-test/suites/show_p0/test_show_delete.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_show_delete") {
def tableName = "test_show_delete_table"
sql """drop table if exists ${tableName}"""

sql """
CREATE TABLE IF NOT EXISTS ${tableName}
(
`datetime` DATE NOT NULL COMMENT "['0000-01-01', '9999-12-31']",
`type` TINYINT NOT NULL COMMENT "[-128, 127]",
`user_id` decimal(9,3) COMMENT "[-9223372036854775808, 9223372036854775807]"
)
UNIQUE KEY(`datetime`)
PARTITION BY RANGE(`datetime`)
(
PARTITION `Feb` VALUES LESS THAN ("2022-03-01"),
PARTITION `Mar` VALUES LESS THAN ("2022-04-01")
)
DISTRIBUTED BY HASH(`datetime`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """insert into ${tableName} values ('2022-02-01', 1, 1.1), ('2022-03-01', 2, 2.2)"""

sql """ set delete_without_partition = true"""
// don't care nereids planner
sql """ delete from ${tableName} PARTITION Mar where type ='2'"""
sql """ delete from ${tableName} where type ='1'"""
def showDeleteResult = sql """ show delete"""
//When we test locally, multiple history results will be included, so size will be >= 2
assert showDeleteResult.size() >= 2
def count = 0
showDeleteResult.each { row ->

if (row[3] == 'type EQ "2"') {
assert row[1] == 'Mar'
count++
return
}
if (row[3] == 'type EQ "1"') {
assert row[1] == '*'
count++
return
}

}
assert count == showDeleteResult.size()

}

0 comments on commit 996ba96

Please sign in to comment.