Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cast primitive for node/relationship #362

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nebula3/data/DataObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ def _cast_node(node: Vertex):
return {
"vid": node.get_id().cast(),
"tags": {
tag_name: node.properties(tag_name) for tag_name in node.tags()
tag_name: {
k: v.cast() for k, v in node.properties(tag_name).items()
}
for tag_name in node.tags()
},
}

Expand All @@ -720,7 +723,7 @@ def _cast_relationship(edge: Edge):
"dst": edge.end_vertex_id().cast(),
"type": edge.edge_name(),
"rank": edge.ranking(),
"props": edge.properties(),
"props": {k: v.cast() for k, v in edge.properties().items()},
}

def _cast_primitive(raw_value):
Expand Down
47 changes: 0 additions & 47 deletions tests/test_data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,6 @@ def test_cast(self):

def test_cast_primitive(self):
# Test casting for primitive types
def _cast_node(node: Vertex):
return {
"vid": node.get_id().cast(),
"tags": {
tag_name: node.properties(tag_name) for tag_name in node.tags()
},
}

def _cast_relationship(edge: Edge):
return {
"src": edge.start_vertex_id().cast(),
"dst": edge.end_vertex_id().cast(),
"type": edge.edge_name(),
"rank": edge.ranking(),
"props": edge.properties(),
}

# Test boolean
bool_val = ttypes.Value(bVal=True)
Expand All @@ -423,37 +407,6 @@ def _cast_relationship(edge: Edge):
null_val = ttypes.Value(nVal=ttypes.NullType.__NULL__)
assert ValueWrapper(null_val).cast_primitive() is None

# Test node
node_val = ttypes.Value(vVal=self.get_vertex_value(b"Tom"))
node = ValueWrapper(node_val).as_node()
assert ValueWrapper(node_val).cast_primitive() == {
"vid": node.get_id().cast(),
"tags": {tag_name: node.properties(tag_name) for tag_name in node.tags()},
}

# Test relationship
relationship_val = ttypes.Value(eVal=self.get_edge_value(b"Tom", b"Lily"))
edge = ValueWrapper(relationship_val).as_relationship()
assert ValueWrapper(relationship_val).cast_primitive() == {
"src": edge.start_vertex_id().cast(),
"dst": edge.end_vertex_id().cast(),
"type": edge.edge_name(),
"rank": edge.ranking(),
"props": edge.properties(),
}

# Test path
path_val = ttypes.Value(pVal=self.get_path_value(b"Tom"))
path_raw = ValueWrapper(path_val)
path = path_raw.as_path()
path_primitive = path_raw.cast_primitive()
assert path_primitive == {
"path_str": path.__repr__(),
"start_node": _cast_node(path.start_node()),
"edges": [_cast_relationship(x) for x in path.relationships()],
"nodes": [_cast_node(x) for x in path.nodes()],
}

# Test geography
geography_val = ttypes.Value(ggVal=self.get_geography_value(3.0, 5.2))
geography_raw = ValueWrapper(geography_val)
Expand Down
Loading