Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions be/src/olap/delete_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TC
// the condition column type should not be float or double.
const TabletColumn& column = schema.column(field_index);

if ((!column.is_key() && schema.keys_type() != KeysType::DUP_KEYS) ||
column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE ||
if (column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE ||
column.type() == FieldType::OLAP_FIELD_TYPE_FLOAT) {
return Status::Error<DELETE_INVALID_CONDITION>(
"field is not key column, or storage model is not duplicate, or data type is float "
"or double.");
return Status::Error<DELETE_INVALID_CONDITION>("data type is float or double.");
}

// Check operator and operands size are matched.
Expand Down
14 changes: 5 additions & 9 deletions be/test/olap/delete_handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ TEST_F(TestDeleteConditionHandler, StoreCondInvalidParameters) {
DeletePredicatePB del_pred;
Status failed_res = DeleteHandler::generate_delete_predicate(*tablet->tablet_schema(),
conditions, &del_pred);
;
EXPECT_EQ(Status::Error<DELETE_INVALID_PARAMETERS>(""), failed_res);
}

Expand All @@ -423,7 +422,6 @@ TEST_F(TestDeleteConditionHandler, StoreCondNonexistentColumn) {
DeletePredicatePB del_pred;
Status failed_res = DeleteHandler::generate_delete_predicate(*tablet->tablet_schema(),
conditions, &del_pred);
;
EXPECT_EQ(Status::Error<DELETE_INVALID_CONDITION>(""), failed_res);

// 'v'是value列
Expand All @@ -434,10 +432,9 @@ TEST_F(TestDeleteConditionHandler, StoreCondNonexistentColumn) {
condition.condition_values.push_back("5");
conditions.push_back(condition);

failed_res = DeleteHandler::generate_delete_predicate(*tablet->tablet_schema(), conditions,
&del_pred);
;
EXPECT_EQ(Status::Error<DELETE_INVALID_CONDITION>(""), failed_res);
Status success_res = DeleteHandler::generate_delete_predicate(*tablet->tablet_schema(),
conditions, &del_pred);
EXPECT_EQ(Status::OK(), success_res);

// value column in duplicate model can be deleted;
conditions.clear();
Expand All @@ -447,9 +444,8 @@ TEST_F(TestDeleteConditionHandler, StoreCondNonexistentColumn) {
condition.condition_values.push_back("5");
conditions.push_back(condition);

Status success_res = DeleteHandler::generate_delete_predicate(*dup_tablet->tablet_schema(),
conditions, &del_pred);
;
success_res = DeleteHandler::generate_delete_predicate(*dup_tablet->tablet_schema(), conditions,
&del_pred);
EXPECT_EQ(Status::OK(), success_res);
}

Expand Down
17 changes: 13 additions & 4 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,19 @@ private void checkDeleteConditions() throws AnalysisException {
// Due to rounding errors, most floating-point numbers end up being slightly imprecise,
// it also means that numbers expected to be equal often differ slightly, so we do not allow compare with
// floating-point numbers, floating-point number not allowed in where clause
if (!column.isKey() && table.getKeysType() != KeysType.DUP_KEYS
|| column.getDataType().isFloatingPointType()) {
throw new AnalysisException("Column[" + columnName + "] is not key column or storage model "
+ "is not duplicate or column type is float or double.");
if (column.getDataType().isFloatingPointType()) {
throw new AnalysisException("Column[" + columnName + "] type is float or double.");
}
if (!column.isKey()) {
if (table.getKeysType() == KeysType.AGG_KEYS) {
throw new AnalysisException("delete predicate on value column only supports Unique table with"
+ " merge-on-write enabled and Duplicate table, but " + "Table[" + table.getName()
+ "] is an Aggregate table.");
} else if (table.getKeysType() == KeysType.UNIQUE_KEYS && !table.getEnableUniqueKeyMergeOnWrite()) {
throw new AnalysisException("delete predicate on value column only supports Unique table with"
+ " merge-on-write enabled and Duplicate table, but " + "Table[" + table.getName()
+ "] is an Aggregate table.");
}
}

if (condition instanceof BinaryPredicate) {
Expand Down
18 changes: 13 additions & 5 deletions fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,19 @@ private void checkDeleteV2(OlapTable table, List<Partition> partitions,
// Due to rounding errors, most floating-point numbers end up being slightly imprecise,
// it also means that numbers expected to be equal often differ slightly, so we do not allow compare with
// floating-point numbers, floating-point number not allowed in where clause
if (!column.isKey() && table.getKeysType() != KeysType.DUP_KEYS
|| column.getDataType().isFloatingPointType()) {
// ErrorReport.reportDdlException(ErrorCode.ERR_NOT_KEY_COLUMN, columnName);
throw new DdlException("Column[" + columnName + "] is not key column or storage model "
+ "is not duplicate or column type is float or double.");
if (column.getDataType().isFloatingPointType()) {
throw new DdlException("Column[" + columnName + "] type is float or double.");
}
if (!column.isKey()) {
if (table.getKeysType() == KeysType.AGG_KEYS) {
throw new DdlException("delete predicate on value column only supports Unique table with"
+ " merge-on-write enabled and Duplicate table, but " + "Table[" + table.getName()
+ "] is an Aggregate table.");
} else if (table.getKeysType() == KeysType.UNIQUE_KEYS && !table.getEnableUniqueKeyMergeOnWrite()) {
throw new DdlException("delete predicate on value column only supports Unique table with"
+ " merge-on-write enabled and Duplicate table, but " + "Table[" + table.getName()
+ "] is an Aggregate table.");
}
}

if (condition instanceof BinaryPredicate) {
Expand Down
94 changes: 94 additions & 0 deletions regression-test/data/delete_p0/test_delete_on_value.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9

-- !sql --
1 1 1
2 2 2
3 3 3
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9

-- !sql --
1 1 1
2 2 2
8 8 8
9 9 9

-- !sql --
1 1 1 0
2 2 2 0
3 3 3 0
4 4 4 0
5 5 5 0
6 6 6 0
7 7 7 0
8 8 8 0
9 9 9 0

-- !sql --
1 1 1
2 2 2
4 4 4
5 5 5
8 8 8
9 9 9

-- !sql --
1 1 1
2 2 2
4 4 4
8 8 8
9 9 9

-- !sql --
1 1 1 0
2 2 2 0
3 3 3 0
4 4 4 0
4 4 4 0
5 5 5 0
5 5 5 0
6 6 6 0
7 7 7 0
8 8 8 0
9 9 9 0

-- !sql --
1 1 10

-- !sql --
1 1 5 0 3 5
1 1 10 0 2 10

-- !sql --

-- !sql --
1 1 5 0 3 5
1 1 10 0 2 10

-- !sql --
1 1 10

-- !sql --
1 1 5 0 3 5
1 1 10 0 2 10

-- !sql --

-- !sql --
1 \N \N 1 4 10
1 1 5 0 3 5
1 1 10 0 2 10

153 changes: 153 additions & 0 deletions regression-test/suites/delete_p0/test_delete_on_value.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// 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_delete_on_value") {
sql 'set enable_nereids_planner=false'
sql "set experimental_enable_nereids_planner=false;"
sql 'set enable_nereids_dml=false'

sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
def tableName = "test_delete_on_value"
sql """ DROP TABLE IF EXISTS ${tableName} """
sql """ CREATE TABLE ${tableName} (
`x` BIGINT NOT NULL,
`y` BIGINT NULL,
`z` BIGINT NULL)
ENGINE=OLAP
UNIQUE KEY(`x`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`x`) BUCKETS 4
PROPERTIES (
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true"
);"""
sql """ insert into ${tableName} values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7),(8,8,8),(9,9,9); """
qt_sql "select * from ${tableName} order by x,y,z;"
sql "delete from ${tableName} where y=4;"
qt_sql "select * from ${tableName} order by x,y,z;"
sql "delete from ${tableName} where z>=3 and z<=7;"
qt_sql "select * from ${tableName} order by x,y,z;"
sql "set skip_delete_predicate=true;"
qt_sql "select x,y,z,__DORIS_DELETE_SIGN__ from ${tableName} order by x,y,z,__DORIS_DELETE_SIGN__;"
sql "set skip_delete_predicate=false;"
sql "insert into ${tableName} values(4,4,4),(5,5,5);"
qt_sql "select * from ${tableName} order by x,y,z;"
sql "delete from ${tableName} where y=5;"
qt_sql "select * from ${tableName} order by x,y,z;"
sql "set skip_storage_engine_merge=true;"
sql "set skip_delete_bitmap=true;"
sql "set skip_delete_predicate=true;"
qt_sql "select x,y,z,__DORIS_DELETE_SIGN__ from ${tableName} order by x,y,z,__DORIS_DELETE_SIGN__;"
sql "DROP TABLE IF EXISTS ${tableName};"


def tableName2 = "test_delete_on_value2"
sql """ DROP TABLE IF EXISTS ${tableName2} """
sql """ CREATE TABLE ${tableName2} (
`x` BIGINT NOT NULL,
`y` BIGINT REPLACE_IF_NOT_NULL NULL,
`z` BIGINT REPLACE_IF_NOT_NULL NULL)
ENGINE=OLAP
AGGREGATE KEY(`x`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`x`) BUCKETS 4
PROPERTIES (
"replication_num" = "1"
);"""
sql """ insert into ${tableName2} values(1,1,1); """
test {
sql "delete from ${tableName2} where y=4;"
exception "delete predicate on value column only supports Unique table with merge-on-write enabled and Duplicate table, but Table[test_delete_on_value2] is an Aggregate table."
}

sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
def tableName3 = "test_delete_on_value_with_seq_col"
sql """ DROP TABLE IF EXISTS ${tableName3} """
sql """ CREATE TABLE ${tableName3} (
`x` BIGINT NOT NULL,
`y` BIGINT NULL,
`z` BIGINT NULL)
ENGINE=OLAP
UNIQUE KEY(`x`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`x`) BUCKETS 4
PROPERTIES (
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true",
"function_column.sequence_col" = "z"
);"""
sql "insert into ${tableName3} values(1,1,10);"
sql "insert into ${tableName3} values(1,1,5);"
qt_sql "select * from ${tableName3} order by x,y,z;"
sql "set skip_storage_engine_merge=true;"
sql "set skip_delete_bitmap=true;"
sql "set skip_delete_predicate=true;"
qt_sql "select * from ${tableName3} order by x,y,z;"
sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
sql "delete from ${tableName3} where z>=10;"
qt_sql "select * from ${tableName3} order by x,y,z;"
sql "set skip_storage_engine_merge=true;"
sql "set skip_delete_bitmap=true;"
sql "set skip_delete_predicate=true;"
qt_sql "select * from ${tableName3} order by x,y,z;"
sql "DROP TABLE IF EXISTS ${tableName3}"

sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
def tableName4 = "test_delete_on_value_with_seq_col_mor"
sql """ DROP TABLE IF EXISTS ${tableName4} """
sql """ CREATE TABLE ${tableName4} (
`x` BIGINT NOT NULL,
`y` BIGINT NULL,
`z` BIGINT NULL)
ENGINE=OLAP
UNIQUE KEY(`x`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`x`) BUCKETS 4
PROPERTIES (
"replication_num" = "1",
"function_column.sequence_col" = "z"
);"""
sql "insert into ${tableName4} values(1,1,10);"
sql "insert into ${tableName4} values(1,1,5);"
qt_sql "select * from ${tableName4} order by x,y,z;"
sql "set skip_storage_engine_merge=true;"
sql "set skip_delete_bitmap=true;"
sql "set skip_delete_predicate=true;"
qt_sql "select * from ${tableName4} order by x,y,z;"
sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
sql "delete from ${tableName4} where z>=10;"
qt_sql "select * from ${tableName4} order by x,y,z;"
sql "set skip_storage_engine_merge=true;"
sql "set skip_delete_bitmap=true;"
sql "set skip_delete_predicate=true;"
qt_sql "select * from ${tableName4} order by x,y,z;"
sql "DROP TABLE IF EXISTS ${tableName4};"

sql "set skip_storage_engine_merge=false;"
sql "set skip_delete_bitmap=false;"
sql "set skip_delete_predicate=false;"
}