Skip to content

Commit

Permalink
fix(interactive): fix comparison between RTAny numeric types (#4399)
Browse files Browse the repository at this point in the history
As titled.

Fix #4396
  • Loading branch information
zhanglei1949 authored Jan 3, 2025
1 parent 30f905e commit 89671f8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
12 changes: 10 additions & 2 deletions flex/engines/graph_db/runtime/adhoc/operators/scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ static bl::result<Context> scan_vertices_no_expr_impl(
std::vector<int64_t> gids;
for (size_t i = 0; i < input_ids.size(); i++) {
if (input_ids[i].type != PropertyType::Int64()) {
RETURN_BAD_REQUEST_ERROR("Expect int64 type for global id");
if (input_ids[i].type == PropertyType::Int32()) {
LOG(WARNING) << "Implicitly convert int32 to int64 when scan vertex "
"with global id";
gids.push_back(input_ids[i].AsInt32());
} else {
RETURN_BAD_REQUEST_ERROR("Expect int64 type for global id, but got" +
input_ids[i].type.ToString());
}
} else {
gids.push_back(input_ids[i].AsInt64());
}
gids.push_back(input_ids[i].AsInt64());
}
return Scan::filter_gids(
txn, scan_params, [](label_t, vid_t) { return true; }, gids);
Expand Down
43 changes: 24 additions & 19 deletions flex/engines/graph_db/runtime/common/rt_any.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,32 +443,44 @@ int RTAny::numerical_cmp(const RTAny& other) const {
switch (type_.type_enum_) {
case RTAnyType::RTAnyTypeImpl::kI64Value:
switch (other.type_.type_enum_) {
case RTAnyType::RTAnyTypeImpl::kI32Value:
return value_.i64_val - other.value_.i32_val;
case RTAnyType::RTAnyTypeImpl::kF64Value:
return value_.i64_val - other.value_.f64_val;
case RTAnyType::RTAnyTypeImpl::kI32Value: {
auto res = value_.i64_val - other.value_.i32_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
case RTAnyType::RTAnyTypeImpl::kF64Value: {
auto res = value_.i64_val - other.value_.f64_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
default:
LOG(FATAL) << "not support for "
<< static_cast<int>(other.type_.type_enum_);
}
break;
case RTAnyType::RTAnyTypeImpl::kI32Value:
switch (other.type_.type_enum_) {
case RTAnyType::RTAnyTypeImpl::kI64Value:
return value_.i32_val - other.value_.i64_val;
case RTAnyType::RTAnyTypeImpl::kF64Value:
return value_.i32_val - other.value_.f64_val;
case RTAnyType::RTAnyTypeImpl::kI64Value: {
auto res = value_.i32_val - other.value_.i64_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
case RTAnyType::RTAnyTypeImpl::kF64Value: {
auto res = value_.i32_val - other.value_.f64_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
default:
LOG(FATAL) << "not support for "
<< static_cast<int>(other.type_.type_enum_);
}
break;
case RTAnyType::RTAnyTypeImpl::kF64Value:
switch (other.type_.type_enum_) {
case RTAnyType::RTAnyTypeImpl::kI64Value:
return value_.f64_val - other.value_.i64_val;
case RTAnyType::RTAnyTypeImpl::kI32Value:
return value_.f64_val - other.value_.i32_val;
case RTAnyType::RTAnyTypeImpl::kI64Value: {
auto res = value_.f64_val - other.value_.i64_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
case RTAnyType::RTAnyTypeImpl::kI32Value: {
auto res = value_.f64_val - other.value_.i32_val;
return res > 0 ? 1 : (res == 0 ? 0 : -1);
}
default:
LOG(FATAL) << "not support for " << static_cast<int>(type_.type_enum_);
}
Expand Down Expand Up @@ -528,13 +540,6 @@ bool RTAny::operator==(const RTAny& other) const {
return value_.vertex == other.value_.vertex;
} else if (type_ == RTAnyType::kDate32) {
return value_.i64_val == other.value_.i64_val;
}

if (type_ == RTAnyType::kI64Value && other.type_ == RTAnyType::kI32Value) {
return value_.i64_val == other.value_.i32_val;
} else if (type_ == RTAnyType::kI32Value &&
other.type_ == RTAnyType::kI64Value) {
return value_.i32_val == other.value_.i64_val;
} else if (type_ == RTAnyType::kF64Value) {
return value_.f64_val == other.value_.f64_val;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,10 @@ public static QueryContext get_graph_algo_test13() {
+ " 1}>");
return new QueryContext(query, expected);
}

public static QueryContext get_graph_algo_test14() {
String query = "MATCH(a) where elementId(a) in [0] return a.id;";
List<String> expected = Arrays.asList("Record<{id: 0}>");
return new QueryContext(query, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public void run_graph_query13_test() {
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
}

@Test
public void run_graph_query14_test() {
QueryContext testQuery = GraphAlgoQueries.get_graph_algo_test14();
Result result = session.run(testQuery.getQuery());
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
}

@AfterClass
public static void afterClass() {
if (session != null) {
Expand Down

0 comments on commit 89671f8

Please sign in to comment.