mirror of https://github.com/milvus-io/milvus.git
Fix BinaryArithOpEvalRange integer overflow case (#24943)
Signed-off-by: longjiquan <jiquan.long@zilliz.com>pull/24921/head
parent
3b5b50bda8
commit
8885fa2bc7
|
@ -306,21 +306,30 @@ Parser::ParseRangeNodeImpl(const FieldName& field_name, const Json& body) {
|
|||
} else if constexpr (std::is_integral_v<T>) {
|
||||
Assert(right_operand.is_number_integer());
|
||||
Assert(value.is_number_integer());
|
||||
// see also: https://github.com/milvus-io/milvus/issues/23646.
|
||||
return std::make_unique<
|
||||
BinaryArithOpEvalRangeExprImpl<int64_t>>(
|
||||
ColumnInfo(schema.get_field_id(field_name),
|
||||
schema[field_name].get_data_type()),
|
||||
proto::plan::GenericValue::ValCase::kInt64Val,
|
||||
arith_op_mapping_.at(arith_op_name),
|
||||
right_operand,
|
||||
mapping_.at(op_name),
|
||||
value);
|
||||
} else if constexpr (std::is_floating_point_v<T>) {
|
||||
Assert(right_operand.is_number());
|
||||
Assert(value.is_number());
|
||||
return std::make_unique<BinaryArithOpEvalRangeExprImpl<T>>(
|
||||
ColumnInfo(schema.get_field_id(field_name),
|
||||
schema[field_name].get_data_type()),
|
||||
proto::plan::GenericValue::ValCase::kFloatVal,
|
||||
arith_op_mapping_.at(arith_op_name),
|
||||
right_operand,
|
||||
mapping_.at(op_name),
|
||||
value);
|
||||
} else {
|
||||
static_assert(always_false<T>, "unsupported type");
|
||||
}
|
||||
|
||||
return std::make_unique<BinaryArithOpEvalRangeExprImpl<T>>(
|
||||
ColumnInfo(schema.get_field_id(field_name),
|
||||
schema[field_name].get_data_type()),
|
||||
proto::plan::GenericValue::ValCase::VAL_NOT_SET,
|
||||
arith_op_mapping_.at(arith_op_name),
|
||||
right_operand,
|
||||
mapping_.at(op_name),
|
||||
value);
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<T, bool>) {
|
||||
|
|
|
@ -514,22 +514,15 @@ ProtoParser::ParseBinaryArithOpEvalRangeExpr(
|
|||
|
||||
auto result = [&]() -> ExprPtr {
|
||||
switch (data_type) {
|
||||
case DataType::INT8: {
|
||||
return ExtractBinaryArithOpEvalRangeExprImpl<int8_t>(
|
||||
field_id, data_type, expr_pb);
|
||||
}
|
||||
case DataType::INT16: {
|
||||
return ExtractBinaryArithOpEvalRangeExprImpl<int16_t>(
|
||||
field_id, data_type, expr_pb);
|
||||
}
|
||||
case DataType::INT32: {
|
||||
return ExtractBinaryArithOpEvalRangeExprImpl<int32_t>(
|
||||
field_id, data_type, expr_pb);
|
||||
}
|
||||
// see also: https://github.com/milvus-io/milvus/issues/23646.
|
||||
case DataType::INT8:
|
||||
case DataType::INT16:
|
||||
case DataType::INT32:
|
||||
case DataType::INT64: {
|
||||
return ExtractBinaryArithOpEvalRangeExprImpl<int64_t>(
|
||||
field_id, data_type, expr_pb);
|
||||
}
|
||||
|
||||
case DataType::FLOAT: {
|
||||
return ExtractBinaryArithOpEvalRangeExprImpl<float>(
|
||||
field_id, data_type, expr_pb);
|
||||
|
|
|
@ -585,13 +585,18 @@ template <typename T>
|
|||
auto
|
||||
ExecExprVisitor::ExecBinaryArithOpEvalRangeVisitorDispatcher(
|
||||
BinaryArithOpEvalRangeExpr& expr_raw) -> BitsetType {
|
||||
auto& expr = static_cast<BinaryArithOpEvalRangeExprImpl<T>&>(expr_raw);
|
||||
// see also: https://github.com/milvus-io/milvus/issues/23646.
|
||||
typedef std::conditional_t<std::is_integral_v<T>, int64_t, T>
|
||||
HighPrecisionType;
|
||||
|
||||
auto& expr =
|
||||
static_cast<BinaryArithOpEvalRangeExprImpl<HighPrecisionType>&>(
|
||||
expr_raw);
|
||||
using Index = index::ScalarIndex<T>;
|
||||
auto arith_op = expr.arith_op_;
|
||||
auto right_operand = expr.right_operand_;
|
||||
auto op = expr.op_type_;
|
||||
auto val = expr.value_;
|
||||
auto& nested_path = expr.column_.nested_path;
|
||||
|
||||
switch (op) {
|
||||
case OpType::Equal: {
|
||||
|
@ -602,12 +607,9 @@ ExecExprVisitor::ExecBinaryArithOpEvalRangeVisitorDispatcher(
|
|||
auto x = index->Reverse_Lookup(offset);
|
||||
return (x + right_operand) == val;
|
||||
};
|
||||
auto elem_func =
|
||||
[val, right_operand, &nested_path](MayConstRef<T> x) {
|
||||
// visit the nested field
|
||||
// now it must be Json
|
||||
return ((x + right_operand) == val);
|
||||
};
|
||||
auto elem_func = [val, right_operand](MayConstRef<T> x) {
|
||||
return ((x + right_operand) == val);
|
||||
};
|
||||
return ExecDataRangeVisitorImpl<T>(
|
||||
expr.column_.field_id, index_func, elem_func);
|
||||
}
|
||||
|
|
|
@ -299,18 +299,14 @@ ShowExprVisitor::visit(BinaryArithOpEvalRangeExpr& expr) {
|
|||
AssertInfo(datatype_is_vector(expr.column_.data_type) == false,
|
||||
"[ShowExprVisitor]Data type of expr isn't vector type");
|
||||
switch (expr.column_.data_type) {
|
||||
// see also: https://github.com/milvus-io/milvus/issues/23646.
|
||||
case DataType::INT8:
|
||||
json_opt_ = BinaryArithOpEvalRangeExtract<int8_t>(expr);
|
||||
return;
|
||||
case DataType::INT16:
|
||||
json_opt_ = BinaryArithOpEvalRangeExtract<int16_t>(expr);
|
||||
return;
|
||||
case DataType::INT32:
|
||||
json_opt_ = BinaryArithOpEvalRangeExtract<int32_t>(expr);
|
||||
return;
|
||||
case DataType::INT64:
|
||||
json_opt_ = BinaryArithOpEvalRangeExtract<int64_t>(expr);
|
||||
return;
|
||||
|
||||
case DataType::DOUBLE:
|
||||
json_opt_ = BinaryArithOpEvalRangeExtract<double>(expr);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue