fix: Fixes get_filtered_graph_data in kuzu adapter
output format is same as the othere adpaters get_filtered_graph_data. <!-- .github/pull_request_template.md --> ## Description <!-- Please provide a clear, human-generated description of the changes in this PR. DO NOT use AI-generated descriptions. We want to understand your thought process and reasoning. --> ## Type of Change <!-- Please check the relevant option --> - [-] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Changes Made <!-- List the specific changes made in this PR --> Only minimal changes are made in the file for adapter for kuzu database. ## Testing <!-- Describe how you tested your changes --> ## Screenshots/Videos (if applicable) <!-- Add screenshots or videos to help explain your changes --> ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [-] **I have tested my changes thoroughly before submitting this PR** - [-] **This PR contains minimal changes necessary to address the issue/feature** - [-] My code follows the project's coding standards and style guidelines - [-] I have added tests that prove my fix is effective or that my feature works - [-] I have added necessary documentation (if applicable) - [-] All new and existing tests pass - [-] I have searched existing PRs to ensure this change hasn't been submitted already - [-] I have linked any relevant issues in the description - [-] My commits have clear and descriptive messages ## Related Issues <!-- Link any related issues using "Fixes #issue_number" or "Relates to #issue_number" --> #1436 ## Additional Notes <!-- Add any additional notes, concerns, or context for reviewers --> ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --------- Co-authored-by: hajdul88 <52442977+hajdul88@users.noreply.github.com>
This commit is contained in:
parent
38b83a5ec1
commit
03858bc06b
1 changed files with 37 additions and 4 deletions
|
|
@ -1277,7 +1277,6 @@ class KuzuAdapter(GraphDBInterface):
|
|||
A tuple containing a list of filtered node properties and a list of filtered edge
|
||||
properties.
|
||||
"""
|
||||
|
||||
where_clauses = []
|
||||
params = {}
|
||||
|
||||
|
|
@ -1288,16 +1287,50 @@ class KuzuAdapter(GraphDBInterface):
|
|||
params[param_name] = values
|
||||
|
||||
where_clause = " AND ".join(where_clauses)
|
||||
nodes_query = f"MATCH (n:Node) WHERE {where_clause} RETURN properties(n)"
|
||||
nodes_query = (
|
||||
f"MATCH (n:Node) WHERE {where_clause} RETURN n.id, {{properties: n.properties}}"
|
||||
)
|
||||
edges_query = f"""
|
||||
MATCH (n1:Node)-[r:EDGE]->(n2:Node)
|
||||
WHERE {where_clause.replace("n.", "n1.")} AND {where_clause.replace("n.", "n2.")}
|
||||
RETURN properties(r)
|
||||
RETURN n1.id, n2.id, r.relationship_name, r.properties
|
||||
"""
|
||||
nodes, edges = await asyncio.gather(
|
||||
self.query(nodes_query, params), self.query(edges_query, params)
|
||||
)
|
||||
return ([n[0] for n in nodes], [e[0] for e in edges])
|
||||
formatted_nodes = []
|
||||
for n in nodes:
|
||||
if n[0]:
|
||||
node_id = str(n[0])
|
||||
props = n[1]
|
||||
if props.get("properties"):
|
||||
try:
|
||||
additional_props = json.loads(props["properties"])
|
||||
props.update(additional_props)
|
||||
del props["properties"]
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"Failed to parse properties JSON for node {node_id}")
|
||||
formatted_nodes.append((node_id, props))
|
||||
if not formatted_nodes:
|
||||
logger.warning("No nodes found in the database")
|
||||
return [], []
|
||||
|
||||
formatted_edges = []
|
||||
for e in edges:
|
||||
if e and len(e) >= 3:
|
||||
source_id = str(e[0])
|
||||
target_id = str(e[1])
|
||||
rel_type = str(e[2])
|
||||
props = {}
|
||||
if len(e) > 3 and e[3]:
|
||||
try:
|
||||
props = json.loads(e[3])
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
logger.warning(
|
||||
f"Failed to parse edge properties for {source_id}->{target_id}"
|
||||
)
|
||||
formatted_edges.append((source_id, target_id, rel_type, props))
|
||||
return formatted_nodes, formatted_edges
|
||||
|
||||
async def get_graph_metrics(self, include_optional=False) -> Dict[str, Any]:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue