diff --git a/flex/engines/graph_db/runtime/common/rt_any.cc b/flex/engines/graph_db/runtime/common/rt_any.cc index b0f979e9b1d0..44944415c659 100644 --- a/flex/engines/graph_db/runtime/common/rt_any.cc +++ b/flex/engines/graph_db/runtime/common/rt_any.cc @@ -722,8 +722,19 @@ void sink_vertex(const GraphReadInterface& graph, const VertexRecord& vertex, results::Vertex* v) { v->mutable_label()->set_id(vertex.label_); v->set_id(encode_unique_vertex_id(vertex.label_, vertex.vid_)); - // TODO: add properties const auto& names = graph.schema().get_vertex_property_names(vertex.label_); + // Add primary keys first, since primary keys are also the properties of a + // vertex + auto& primary_key = graph.schema().get_vertex_primary_key(vertex.label_); + if (primary_key.size() > 1) { + LOG(ERROR) << "Currently only support single primary key"; + } + auto pk_name = std::get<1>(primary_key[0]); + auto pk_prop = v->add_properties(); + pk_prop->mutable_key()->set_name(pk_name); + sink_any(graph.GetVertexId(vertex.label_, vertex.vid_), + pk_prop->mutable_value()); + for (size_t i = 0; i < names.size(); ++i) { auto prop = v->add_properties(); prop->mutable_key()->set_name(names[i]); diff --git a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py index 95e1c9db1807..83f01adf9ca0 100644 --- a/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py +++ b/flex/interactive/sdk/python/gs_interactive/tests/test_robustness.py @@ -377,6 +377,9 @@ def test_x_csr_params( start_service_on_graph( interactive_session, create_graph_algo_graph_with_x_csr_params ) + ensure_compiler_schema_ready( + interactive_session, neo4j_session, create_graph_algo_graph_with_x_csr_params + ) result = neo4j_session.run('MATCH (n) where n.id <> "" return count(n);') # expect return value 0 records = result.fetch(1) @@ -392,6 +395,9 @@ def test_var_char_property( interactive_session, create_graph_with_var_char_property ) start_service_on_graph(interactive_session, create_graph_with_var_char_property) + ensure_compiler_schema_ready( + interactive_session, neo4j_session, create_graph_with_var_char_property + ) result = neo4j_session.run("MATCH (n: person) return n.name AS personName;") records = result.fetch(10) assert len(records) == 4 diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/simple/SimpleMatchQueries.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/simple/SimpleMatchQueries.java index f027b644fcf1..8c0af5129538 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/simple/SimpleMatchQueries.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/simple/SimpleMatchQueries.java @@ -230,4 +230,21 @@ public static QueryContext get_simple_match_query_18_test() { List expected = Arrays.asList("Record<{$f0: 39783}>"); return new QueryContext(query, expected); } + + public static QueryContext get_simple_match_query_19_test() { + String query = "MATCH(a: PLACE) return a ORDER BY a.id limit 5;"; + List expected = + Arrays.asList( + "[a: {name=India, id=0, type=country," + + " url=http://dbpedia.org/resource/India}]", + "[a: {name=China, id=1, type=country," + + " url=http://dbpedia.org/resource/China}]", + "[a: {name=Angola, id=2, type=country," + + " url=http://dbpedia.org/resource/Angola}]", + "[a: {name=Austria, id=3, type=country," + + " url=http://dbpedia.org/resource/Austria}]", + "[a: {name=Azerbaijan, id=4, type=country," + + " url=http://dbpedia.org/resource/Azerbaijan}]"); + return new QueryContext(query, expected); + } } diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/ldbc/SimpleMatchTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/ldbc/SimpleMatchTest.java index 48b8e60fcfbf..60751a462bee 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/ldbc/SimpleMatchTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/ldbc/SimpleMatchTest.java @@ -25,11 +25,23 @@ import org.junit.BeforeClass; import org.junit.Test; import org.neo4j.driver.GraphDatabase; +import org.neo4j.driver.Record; import org.neo4j.driver.Result; import org.neo4j.driver.Session; +import org.neo4j.driver.Value; +import org.neo4j.driver.internal.types.InternalTypeSystem; +import org.neo4j.driver.types.Node; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class SimpleMatchTest { + private static final Logger logger = LoggerFactory.getLogger(SimpleMatchTest.class); + private static Session session; @BeforeClass @@ -169,6 +181,38 @@ public void run_simple_match_18_test() { Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); } + @Test + public void run_simple_match_19_test() { + assumeTrue("hiactor".equals(System.getenv("ENGINE_TYPE"))); + QueryContext testQuery = SimpleMatchQueries.get_simple_match_query_19_test(); + Result result = session.run(testQuery.getQuery()); + List records = result.list(); + List properties = new ArrayList<>(); + records.forEach( + record -> { + properties.add(fetchAllProperties(record)); + }); + logger.info(properties.toString()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), properties.toString()); + } + + private static String fetchAllProperties(Record record) { + List properties = new ArrayList<>(); + record.keys() + .forEach( + key -> { + Value v = record.get(key); + if (v.hasType(InternalTypeSystem.TYPE_SYSTEM.NODE())) { + Node node = v.asNode(); + Map nodeProperties = node.asMap(); + properties.add(key + ": " + nodeProperties.toString()); + } else { + properties.add(key + ": " + record.get(key).toString()); + } + }); + return properties.toString(); + } + @AfterClass public static void afterClass() { if (session != null) {