Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Jul 16, 2024
1 parent 57aed73 commit 3ffbf3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
6 changes: 1 addition & 5 deletions be/src/common/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ void Status::to_thrift(TStatus* s) const {
// DCHECK(_code > 0)
// << "The error code has to > 0 because TStatusCode need it > 0, it's actual value is "
// << _code;
s->status_code = (int16_t)_code > 0 ? (TStatusCode::type)_code
: ((_code == ErrorCode::DELETE_INVALID_CONDITION ||
_code == ErrorCode::DELETE_INVALID_PARAMETERS)
? TStatusCode::INVALID_ARGUMENT
: TStatusCode::INTERNAL_ERROR);
s->status_code = (int16_t)_code > 0 ? (TStatusCode::type)_code : TStatusCode::INTERNAL_ERROR;
s->error_msgs.push_back(fmt::format("({})[{}]{}", BackendOptions::get_localhost(),
code_as_string(), _err_msg ? _err_msg->_msg : ""));
s->__isset.error_msgs = true;
Expand Down
35 changes: 17 additions & 18 deletions be/src/olap/delete_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Status DeleteHandler::generate_delete_predicate(const TabletSchema& schema,
dp->param<std::string>("error_msg"));
})
if (conditions.empty()) {
return Status::Error<DELETE_INVALID_PARAMETERS>(
return Status::Error<ErrorCode::INVALID_ARGUMENT>(
"invalid parameters for store_cond. condition_size={}", conditions.size());
}

Expand Down Expand Up @@ -127,7 +127,7 @@ Status DeleteHandler::generate_delete_predicate(const TabletSchema& schema,
if (TCondition tmp; !DeleteHandler::parse_condition(condition_str, &tmp)) {
LOG(WARNING) << "failed to parse condition_str, condtion="
<< ThriftDebugString(condition);
return Status::Error<DELETE_INVALID_CONDITION>(
return Status::Error<ErrorCode::INVALID_ARGUMENT>(
"failed to parse condition_str, condtion={}", ThriftDebugString(condition));
}
VLOG_NOTICE << __PRETTY_FUNCTION__ << " condition_str: " << condition_str;
Expand Down Expand Up @@ -235,8 +235,8 @@ Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TC
// Check whether the column exists
int32_t field_index = schema.field_index(cond.column_name);
if (field_index < 0) {
return Status::Error<DELETE_INVALID_CONDITION>("field is not existent. [field_index={}]",
field_index);
return Status::Error<ErrorCode::INVALID_ARGUMENT>("field is not existent. [field_index={}]",
field_index);
}

// Delete condition should only applied on key columns or duplicate key table, and
Expand All @@ -245,21 +245,21 @@ Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TC

if (column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE ||
column.type() == FieldType::OLAP_FIELD_TYPE_FLOAT) {
return Status::Error<DELETE_INVALID_CONDITION>("data type is float or double.");
return Status::Error<ErrorCode::INVALID_ARGUMENT>("data type is float or double.");
}

// Check operator and operands size are matched.
if ("*=" != cond.condition_op && "!*=" != cond.condition_op &&
cond.condition_values.size() != 1) {
return Status::Error<DELETE_INVALID_CONDITION>("invalid condition value size. [size={}]",
cond.condition_values.size());
return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value size. [size={}]",
cond.condition_values.size());
}

// Check each operand is valid
for (const auto& condition_value : cond.condition_values) {
if (!is_condition_value_valid(column, cond.condition_op, condition_value)) {
return Status::Error<DELETE_INVALID_CONDITION>("invalid condition value. [value={}]",
condition_value);
return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value. [value={}]",
condition_value);
}
}

Expand All @@ -270,11 +270,10 @@ Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TC
return Status::OK();
}
if (schema.field_index(cond.column_unique_id) == -1) {
const auto& err_msg = fmt::format(
"column id does not exists in table={}, schema "
"version={},",
schema.table_id(), schema.schema_version());
return Status::Error<DELETE_INVALID_CONDITION>(err_msg);
const auto& err_msg =
fmt::format("column id does not exists in table={}, schema version={},",
schema.table_id(), schema.schema_version());
return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg);
}
if (!iequal(schema.column_by_uid(cond.column_unique_id).name(), cond.column_name)) {
const auto& err_msg = fmt::format(
Expand All @@ -283,15 +282,15 @@ Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TC
"delete_cond.column_name ={}",
cond.column_name, cond.column_unique_id,
schema.column_by_uid(cond.column_unique_id).name(), cond.column_name);
return Status::Error<DELETE_INVALID_CONDITION>(err_msg);
return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg);
}

return Status::OK();
}

Status DeleteHandler::parse_condition(const DeleteSubPredicatePB& sub_cond, TCondition* condition) {
if (!sub_cond.has_column_name() || !sub_cond.has_op() || !sub_cond.has_cond_value()) {
return Status::Error<DELETE_INVALID_PARAMETERS>(
return Status::Error<ErrorCode::INVALID_ARGUMENT>(
"fail to parse condition. condition={} {} {}", sub_cond.column_name(),
sub_cond.op(), sub_cond.cond_value());
}
Expand Down Expand Up @@ -337,8 +336,8 @@ Status DeleteHandler::parse_condition(const std::string& condition_str, TConditi
<< "]";
}
if (!matched) {
return Status::Error<DELETE_INVALID_PARAMETERS>("fail to sub condition. condition={}",
condition_str);
return Status::Error<ErrorCode::INVALID_ARGUMENT>("fail to sub condition. condition={}",
condition_str);
}

condition->column_name = what[1].str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,9 @@ suite("test_delete_from_timeout","nonConcurrent") {
try {
sql "insert into ${tableName} values(1, 99.9, 234), (false, -9999782574499444.2, -25);"
qt_sql "select * from ${tableName} order by col1, col2, col3;"
GetDebugPoint().enableDebugPointForAllBEs("DeleteHandler::generate_delete_predicate.inject_failure",
[error_code: -1900 /* DELETE_INVALID_CONDITION */, error_msg: "DELETE_INVALID_CONDITION: data type is float or double."])
test {
sql """delete from ${tableName} where col1 = "false" and col2 = "-9999782574499444.2" and col3 = "-25"; """
exception "data type is float or double."
}

GetDebugPoint().clearDebugPointsForAllBEs()

GetDebugPoint().enableDebugPointForAllBEs("DeleteHandler::generate_delete_predicate.inject_failure",
[error_code: -1903 /* DELETE_INVALID_PARAMETERS */, error_msg: "DELETE_INVALID_PARAMETERS: invalid parameters for store_cond. condition_size=1"])
[error_code: 33 /* INVALID_ARGUMENT */, error_msg: "invalid parameters for store_cond. condition_size=1"])
test {
sql """delete from ${tableName} where col1 = "false" and col2 = "-9999782574499444.2" and col3 = "-25"; """
exception "invalid parameters for store_cond. condition_size=1"
Expand Down

0 comments on commit 3ffbf3a

Please sign in to comment.