atharrva01 commented on PR #385:
URL: https://github.com/apache/hugegraph-ai/pull/385#issuecomment-6976136847

   Live validation against a real HugeGraph 1.7.0 server, as requested in the 
review.
   
   **Setup**
   - HugeGraph Server 1.7.0, the official binary release from 
downloads.apache.org (SHA-512 checked), RocksDB backend, auth off. It runs on 
OpenJDK 11. On JDK 21 the server's Groovy engine fails to start (`Unsupported 
class file major version 65`).
   - Schema: vertex label `person`, edge label `author's friend`, property key 
`owner's name` with a secondary index (HugeGraph only accepts `has()` on 
indexed properties). Two vertices `1:alice --[author's friend]--> 1:bob`.
   - Each run calls the real `GraphQueryNode._subgraph_query` through the real 
`PyHugeClient`, with no fake endpoint. Edge labels come from the live schema 
(`_schema` left empty). The same script runs on `main` (1a1e269) and on this 
branch (f341f83).
   
   **Results**
   
   | Path | `main` | this PR |
   |---|---|---|
   | Vertex-ID path, edge label `author's friend` | server rejects: `unexpected 
token: s` | runs, returns `1:alice{...}--[author's friend]-->1:bob{...}` |
   | Property path, `prop_to_match = "owner's name"` | server rejects: 
`unexpected token: s` | server accepts and returns 1 path |
   
   On `main` the server rejects both queries before running them:
   ```
   bothE('author's friend').limit(8).otherV().dedup()
                       ^  unexpected token: s
   g.V().has('owner's name', within('Alice'))
                       ^  unexpected token: s
   ```
   On this branch the server runs both queries as sent:
   ```
   bothE('author\'s friend').limit(8).otherV().dedup()          -> server OK, 1 
result
   g.V().has('owner\'s name', within('Alice')) ... values('owner\'s name') -> 
server OK, 1 result
   ```
   
   **Separate, older issue (out of scope here):** in the property path the 
query now runs, but `_process_vertex` then raises `KeyError: 'id'`. 
`PROPERTY_QUERY_NEIGHBOR_TPL` projects vertices as `('label', 'props')` with no 
`id`, but `_process_vertex` reads `item['id']`. It also happens on `main` with 
plain names (indexed property `genre`, edge `cites`), so this PR didn't cause 
it. On `main` the parse error simply hid it. I'll open a separate PR for it.
   
   <details><summary>Validation script</summary>
   
   ```python
   """Live validation for apache/hugegraph-ai#385 against a real HugeGraph 
server.
   
   Runs the real GraphQueryNode._subgraph_query (no fake endpoint) through the 
real
   PyHugeClient, on whatever checkout is on sys.path, and prints every Gremlin 
script
   sent to the server plus the server's answer or error.
   
   Usage (from <checkout>/hugegraph-llm/src):
       uv run python live_validate_385.py setup   # create schema + data (once)
       uv run python live_validate_385.py run
   """
   
   import json
   import sys
   
   from pyhugegraph.client import PyHugeClient
   
   from hugegraph_llm.nodes.hugegraph_node.graph_query_node import 
GraphQueryNode
   
   URL, GRAPH, USER, PWD = "http://127.0.0.1:8080";, "hugegraph", "admin", 
"admin"
   EDGE_LABEL = "author's friend"
   PROP_KEY = "owner's name"
   
   
   def client():
       return PyHugeClient(url=URL, graph=GRAPH, user=USER, pwd=PWD)
   
   
   def setup():
       c = client()
       s = c.schema()
       s.propertyKey("name").asText().ifNotExist().create()
       s.propertyKey(PROP_KEY).asText().ifNotExist().create()
       s.vertexLabel("person").properties("name", 
PROP_KEY).primaryKeys("name").ifNotExist().create()
       
s.edgeLabel(EDGE_LABEL).sourceLabel("person").targetLabel("person").ifNotExist().create()
       # HugeGraph only allows has() on indexed properties, so prop_to_match 
needs an index.
       
s.indexLabel("personByOwnersName").onV("person").by(PROP_KEY).secondary().ifNotExist().create()
       g = c.graph()
       alice = g.addVertex("person", {"name": "alice", PROP_KEY: "Alice"})
       bob = g.addVertex("person", {"name": "bob", PROP_KEY: "Bob"})
       g.addEdge(EDGE_LABEL, alice.id, bob.id, {})
       print("schema edge labels:", [e.name for e in s.getEdgeLabels()])
       print("schema property keys:", [p.name for p in s.getPropertyKeys()])
       print("vertices:", alice.id, bob.id)
   
   
   class LoggingGremlin:
       def __init__(self, inner):
           self._inner = inner
   
       def exec(self, gremlin):
           print("----- Gremlin sent to server -----")
           print(gremlin.strip())
           try:
               res = self._inner.exec(gremlin=gremlin)
           except Exception as e:  # report the server's own error verbatim
               print(f"----- SERVER ERROR: {type(e).__name__}: {e}")
               raise
           print(f"----- server OK, {len(res['data'])} result(s)")
           return res
   
   
   def node_with_live_client():
       real = client()
       node = GraphQueryNode()
       node._client = real
       gremlin_factory = real.gremlin
       real.gremlin = lambda: LoggingGremlin(gremlin_factory())
       node._schema = ""  # force the real schema read from the server
       node._prop_to_match = None
       node._max_deep = 2
       node._max_items = 30
       return node
   
   
   def run_case(title, fn):
       print(f"\n========== {title} ==========")
       try:
           ctx = fn()
           print("RESULT graph_result:", 
json.dumps(sorted(ctx.get("graph_result", [])), ensure_ascii=False))
       except Exception as e:
           print(f"RESULT FAILED: {type(e).__name__}")
   
   
   def run():
       run_case(
           f"vertex-id path, edge label {EDGE_LABEL!r}",
           lambda: node_with_live_client()._subgraph_query({"match_vids": 
["1:alice"]}),
       )
   
       def prop_path():
           node = node_with_live_client()
           node._prop_to_match = PROP_KEY
           return node._subgraph_query({"keywords": ["Alice"]})
   
       run_case(f"property path, prop_to_match {PROP_KEY!r}", prop_path)
   
   
   if __name__ == "__main__":
       {"setup": setup, "run": run}[sys.argv[1]]()
   ```
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to