Skip to content

Commit

Permalink
feat(delVerticesByType): add async version, refactor sync version
Browse files Browse the repository at this point in the history
  • Loading branch information
parkererickson-tg committed Oct 28, 2024
1 parent 4e063c4 commit a3f3365
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
11 changes: 11 additions & 0 deletions pyTigerGraph/common/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def _prep_del_vertices_by_id(restppUrl: str, graphname: str,
url2 += ("&" if url2 else "?") + "timeout=" + str(timeout)
return url1, url2, vids

def _prep_del_vertices_by_type(restppUrl: str,
graphname: str,
vertexType: str,
ack: str,
permanent: bool):
'''url builder for delVerticesByType()'''
url = restppUrl + "/graph/" + graphname + "/vertices/" + vertexType + "?ack=" + ack.lower()
if permanent:
url += "&permanent=true"
return url

def vertexSetToDataFrame(vertexSet: list, withId: bool = True,
withType: bool = False) -> 'pd.DataFrame':
"""Converts a vertex set to Pandas DataFrame.
Expand Down
14 changes: 9 additions & 5 deletions pyTigerGraph/pyTigerGraphVertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
_prep_get_vertices_by_id,
_parse_get_vertex_stats,
_prep_del_vertices,
_prep_del_vertices_by_id
_prep_del_vertices_by_id,
_prep_del_vertices_by_type
)

from pyTigerGraph.common.schema import _upsert_attrs
Expand Down Expand Up @@ -744,10 +745,13 @@ def delVerticesByType(self, vertexType: str, permanent: bool = False, ack: str =
if ack.lower() not in ["none", "all"]:
raise TigerGraphException("Invalid value for ack parameter. Use 'none' or 'all'.", None)

url = self.restppUrl + "/graph/" + self.graphname + "/vertices/" + vertexType + "?ack=" + ack.lower()
if permanent:
url += "&permanent=true"

url = _prep_del_vertices_by_type(
restppUrl=self.restppUrl,
graphname=self.graphname,
vertexType=vertexType,
ack=ack,
permanent=permanent
)
ret = self._delete(url)["deleted_vertices"]

logger.debug("return: " + str(ret))
Expand Down
51 changes: 46 additions & 5 deletions pyTigerGraph/pytgasync/pyTigerGraphVertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
_prep_get_vertices_by_id,
_parse_get_vertex_stats,
_prep_del_vertices,
_prep_del_vertices_by_id
_prep_del_vertices_by_id,
_prep_del_vertices_by_type
)

from pyTigerGraph.common.schema import _upsert_attrs
from pyTigerGraph.common.vertex import vertexSetToDataFrame as _vS2DF
from pyTigerGraph.common.util import _safe_char
from pyTigerGraph.common.exception import TigerGraphException

from pyTigerGraph.pytgasync.pyTigerGraphSchema import AsyncPyTigerGraphSchema
from pyTigerGraph.pytgasync.pyTigerGraphUtils import AsyncPyTigerGraphUtils
Expand Down Expand Up @@ -724,10 +726,49 @@ async def delVerticesById(self, vertexType: str, vertexIds: Union[int, str, list

return ret

# def delVerticesByType(self, vertexType: str, permanent: bool = False):
# TODO Implementation
# TODO DELETE /graph/{graph_name}/delete_by_type/vertices/{vertex_type}/
# TODO Maybe call it truncateVertex[Type] or delAllVertices?
async def delVerticesByType(self, vertexType: str, permanent: bool = False, ack: str = "none") -> int:
"""Deletes all vertices of the specified type.
Args:
vertexType:
The name of the vertex type.
permanent:
If true, the deleted vertex IDs can never be inserted back, unless the graph is
dropped or the graph store is cleared.
ack:
If the parameter is set to "none", the delete operation doesn’t need to get acknowledgment from any GPE.
If it is set to "all" (default), the operation needs to get acknowledgment from all GPEs.
Other values will raise an error.
Returns:
A single number of vertices deleted.
Usage:
```py
conn.delVerticesByType("Person")
```
"""

logger.info("entry: delVerticesByType")
logger.debug("params: " + str(locals()))
if ack.lower() not in ["none", "all"]:
raise TigerGraphException("Invalid value for ack parameter. Use 'none' or 'all'.", None)

url = _prep_del_vertices_by_type(
restppUrl=self.restppUrl,
graphname=self.graphname,
vertexType=vertexType,
ack=ack,
permanent=permanent
)

ret = await self._delete(url)["deleted_vertices"]

logger.debug("return: " + str(ret))
logger.info("exit: delVerticesByType")

return ret


# TODO GET /deleted_vertex_check/{graph_name}

Expand Down

0 comments on commit a3f3365

Please sign in to comment.