From 89671f84bc2b643ecc7c344cfe6bfc57af2edb4b Mon Sep 17 00:00:00 2001 From: Zhang Lei Date: Fri, 3 Jan 2025 11:53:34 +0800 Subject: [PATCH] fix(interactive): fix comparison between RTAny numeric types (#4399) As titled. Fix #4396 --- .../graph_db/runtime/adhoc/operators/scan.cc | 12 +++++- .../engines/graph_db/runtime/common/rt_any.cc | 43 +++++++++++-------- .../suite/graphAlgo/GraphAlgoQueries.java | 6 +++ .../integration/graphAlgo/GraphAlgoTest.java | 7 +++ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/flex/engines/graph_db/runtime/adhoc/operators/scan.cc b/flex/engines/graph_db/runtime/adhoc/operators/scan.cc index d9cff3bfa4de..11df071cc8ce 100644 --- a/flex/engines/graph_db/runtime/adhoc/operators/scan.cc +++ b/flex/engines/graph_db/runtime/adhoc/operators/scan.cc @@ -137,9 +137,17 @@ static bl::result scan_vertices_no_expr_impl( std::vector 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); diff --git a/flex/engines/graph_db/runtime/common/rt_any.cc b/flex/engines/graph_db/runtime/common/rt_any.cc index 68d9eb79c616..0b8b7279050a 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.cc +++ b/flex/engines/graph_db/runtime/common/rt_any.cc @@ -443,10 +443,14 @@ 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(other.type_.type_enum_); @@ -454,10 +458,14 @@ int RTAny::numerical_cmp(const RTAny& other) const { 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(other.type_.type_enum_); @@ -465,10 +473,14 @@ int RTAny::numerical_cmp(const RTAny& other) const { 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(type_.type_enum_); } @@ -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; } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/graphAlgo/GraphAlgoQueries.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/graphAlgo/GraphAlgoQueries.java index 8fa2aa631468..1bd162569eac 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/graphAlgo/GraphAlgoQueries.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/graphAlgo/GraphAlgoQueries.java @@ -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 expected = Arrays.asList("Record<{id: 0}>"); + return new QueryContext(query, expected); + } } diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/graphAlgo/GraphAlgoTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/graphAlgo/GraphAlgoTest.java index 9a071481aa39..2e27507a32cd 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/graphAlgo/GraphAlgoTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/graphAlgo/GraphAlgoTest.java @@ -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) {