Skip to content

Commit 89671f8

Browse files
authoredJan 3, 2025
fix(interactive): fix comparison between RTAny numeric types (#4399)
As titled. Fix #4396
1 parent 30f905e commit 89671f8

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed
 

‎flex/engines/graph_db/runtime/adhoc/operators/scan.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ static bl::result<Context> scan_vertices_no_expr_impl(
137137
std::vector<int64_t> gids;
138138
for (size_t i = 0; i < input_ids.size(); i++) {
139139
if (input_ids[i].type != PropertyType::Int64()) {
140-
RETURN_BAD_REQUEST_ERROR("Expect int64 type for global id");
140+
if (input_ids[i].type == PropertyType::Int32()) {
141+
LOG(WARNING) << "Implicitly convert int32 to int64 when scan vertex "
142+
"with global id";
143+
gids.push_back(input_ids[i].AsInt32());
144+
} else {
145+
RETURN_BAD_REQUEST_ERROR("Expect int64 type for global id, but got" +
146+
input_ids[i].type.ToString());
147+
}
148+
} else {
149+
gids.push_back(input_ids[i].AsInt64());
141150
}
142-
gids.push_back(input_ids[i].AsInt64());
143151
}
144152
return Scan::filter_gids(
145153
txn, scan_params, [](label_t, vid_t) { return true; }, gids);

‎flex/engines/graph_db/runtime/common/rt_any.cc

+24-19
Original file line numberDiff line numberDiff line change
@@ -443,32 +443,44 @@ int RTAny::numerical_cmp(const RTAny& other) const {
443443
switch (type_.type_enum_) {
444444
case RTAnyType::RTAnyTypeImpl::kI64Value:
445445
switch (other.type_.type_enum_) {
446-
case RTAnyType::RTAnyTypeImpl::kI32Value:
447-
return value_.i64_val - other.value_.i32_val;
448-
case RTAnyType::RTAnyTypeImpl::kF64Value:
449-
return value_.i64_val - other.value_.f64_val;
446+
case RTAnyType::RTAnyTypeImpl::kI32Value: {
447+
auto res = value_.i64_val - other.value_.i32_val;
448+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
449+
}
450+
case RTAnyType::RTAnyTypeImpl::kF64Value: {
451+
auto res = value_.i64_val - other.value_.f64_val;
452+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
453+
}
450454
default:
451455
LOG(FATAL) << "not support for "
452456
<< static_cast<int>(other.type_.type_enum_);
453457
}
454458
break;
455459
case RTAnyType::RTAnyTypeImpl::kI32Value:
456460
switch (other.type_.type_enum_) {
457-
case RTAnyType::RTAnyTypeImpl::kI64Value:
458-
return value_.i32_val - other.value_.i64_val;
459-
case RTAnyType::RTAnyTypeImpl::kF64Value:
460-
return value_.i32_val - other.value_.f64_val;
461+
case RTAnyType::RTAnyTypeImpl::kI64Value: {
462+
auto res = value_.i32_val - other.value_.i64_val;
463+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
464+
}
465+
case RTAnyType::RTAnyTypeImpl::kF64Value: {
466+
auto res = value_.i32_val - other.value_.f64_val;
467+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
468+
}
461469
default:
462470
LOG(FATAL) << "not support for "
463471
<< static_cast<int>(other.type_.type_enum_);
464472
}
465473
break;
466474
case RTAnyType::RTAnyTypeImpl::kF64Value:
467475
switch (other.type_.type_enum_) {
468-
case RTAnyType::RTAnyTypeImpl::kI64Value:
469-
return value_.f64_val - other.value_.i64_val;
470-
case RTAnyType::RTAnyTypeImpl::kI32Value:
471-
return value_.f64_val - other.value_.i32_val;
476+
case RTAnyType::RTAnyTypeImpl::kI64Value: {
477+
auto res = value_.f64_val - other.value_.i64_val;
478+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
479+
}
480+
case RTAnyType::RTAnyTypeImpl::kI32Value: {
481+
auto res = value_.f64_val - other.value_.i32_val;
482+
return res > 0 ? 1 : (res == 0 ? 0 : -1);
483+
}
472484
default:
473485
LOG(FATAL) << "not support for " << static_cast<int>(type_.type_enum_);
474486
}
@@ -528,13 +540,6 @@ bool RTAny::operator==(const RTAny& other) const {
528540
return value_.vertex == other.value_.vertex;
529541
} else if (type_ == RTAnyType::kDate32) {
530542
return value_.i64_val == other.value_.i64_val;
531-
}
532-
533-
if (type_ == RTAnyType::kI64Value && other.type_ == RTAnyType::kI32Value) {
534-
return value_.i64_val == other.value_.i32_val;
535-
} else if (type_ == RTAnyType::kI32Value &&
536-
other.type_ == RTAnyType::kI64Value) {
537-
return value_.i32_val == other.value_.i64_val;
538543
} else if (type_ == RTAnyType::kF64Value) {
539544
return value_.f64_val == other.value_.f64_val;
540545
}

‎interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/graphAlgo/GraphAlgoQueries.java

+6
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,10 @@ public static QueryContext get_graph_algo_test13() {
241241
+ " 1}>");
242242
return new QueryContext(query, expected);
243243
}
244+
245+
public static QueryContext get_graph_algo_test14() {
246+
String query = "MATCH(a) where elementId(a) in [0] return a.id;";
247+
List<String> expected = Arrays.asList("Record<{id: 0}>");
248+
return new QueryContext(query, expected);
249+
}
244250
}

‎interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/graphAlgo/GraphAlgoTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ public void run_graph_query13_test() {
141141
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
142142
}
143143

144+
@Test
145+
public void run_graph_query14_test() {
146+
QueryContext testQuery = GraphAlgoQueries.get_graph_algo_test14();
147+
Result result = session.run(testQuery.getQuery());
148+
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
149+
}
150+
144151
@AfterClass
145152
public static void afterClass() {
146153
if (session != null) {

0 commit comments

Comments
 (0)