Skip to content
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
2 changes: 1 addition & 1 deletion pyTigerGraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from pyTigerGraph.pytgasync.pyTigerGraph import AsyncTigerGraphConnection
from pyTigerGraph.common.exception import TigerGraphException

__version__ = "1.8.4"
__version__ = "1.8.5"

__license__ = "Apache 2"
3 changes: 2 additions & 1 deletion pyTigerGraph/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def _error_check(self, res: dict) -> bool:
if "error" in res and res["error"] and res["error"] != "false":
# Endpoint might return string "false" rather than Boolean false
raise TigerGraphException(
res["message"], (res["code"] if "code" in res else None))
res["message"], (res["code"] if "code" in res else None)
)
return False

def _prep_req(self, authMode, headers, url, method, data):
Expand Down
76 changes: 70 additions & 6 deletions pyTigerGraph/pyTigerGraphVertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,86 @@ def getVertexAttrs(self, vertexType: str) -> list:
- "map_type(key_type,value_type)"
and it is a string.
"""
logger.info("entry: getAttributes")
logger.info("entry: getVertexAttrs")
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

et = self.getVertexType(vertexType)
ret = []

for at in et["Attributes"]:
at["AttributeType"]["AttributeType"] = at["AttributeType"].pop("Name")
ret.append(
(at["AttributeName"], self._getAttrType(at["AttributeType"])))
(at["AttributeName"], at["AttributeType"])
)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getAttributes")
logger.info("exit: getVertexAttrs")

return ret

def getVertexVectors(self, vertexType: str) -> list:
"""Returns the names and types of the embedding attributes of the vertex type.

Args:
vertexType:
The name of the vertex type.

Returns:
A list of (vector_name, vector_type) tuples.
The format of vector_type is one of
- "scalar_type"
- "complex_type(scalar_type)"
- "map_type(key_type,value_type)"
and it is a string.
"""
logger.info("entry: getVertexVectors")
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

et = self.getVertexType(vertexType)
ret = []

for vt in et["EmbeddingAttributes"]:
ret.append(
(vt["Name"], vt)
)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getVertexVectors")

return ret

def getVectorStatus(self, vertexType: str, vectorAttr: str = "") -> bool:
"""Check the rebuild status of the vertex type or the embedding attribute

Args:
vertexType:
The name of the vertex type.
vectorAttr:
The name of the vector attribute, optional.

Returns:
a bool indicates whether vector rebuild is done or not

Endpoint:
- `GET /vector/status/{graph_name}/{vertex_type}/[{vector_name}]`
"""
logger.info("entry: getVectorStatus")
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

ret = self._req("GET", self.restppUrl + "/vector/status/" +
self.graphname + "/" + vertexType + "/" + vectorName)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getVectorStatus")

return len(ret["NeedRebuildServers"]) == 0

def getVertexType(self, vertexType: str, force: bool = False) -> dict:
"""Returns the details of the specified vertex type.

Expand Down Expand Up @@ -215,7 +278,7 @@ def upsertVertex(self, vertexType: str, vertexId: str, attributes: dict = None)
```
Example:
```
{"name": "Thorin", points: (10, "+"), "bestScore": (67, "max")}
{"name": "Thorin", points: (10, "+"), "bestScore": (83, "max"), "embedding": [0.1, -0.2, 3.1e-2]}
```
For valid values of `<operator>` see xref:tigergraph-server:API:built-in-endpoints.adoc#_operation_codes[Operation codes].

Expand Down Expand Up @@ -268,7 +331,8 @@ def upsertVertices(self, vertexType: str, vertices: list, atomic: bool = False)
----
[
(2, {"name": "Balin", "points": (10, "+"), "bestScore": (67, "max")}),
(3, {"name": "Dwalin", "points": (7, "+"), "bestScore": (35, "max")})
(3, {"name": "Dwalin", "points": (7, "+"), "bestScore": (35, "max")}),
(4, {"name": "Thorin", points: (10, "+"), "bestScore": (83, "max"), "embedding": [0.1, -0.2, 3.1e-2]})
]
----

Expand Down Expand Up @@ -799,4 +863,4 @@ def vertexSetToDataFrame(self, vertexSet: dict, withId: bool = True, withType: b
logger.debug("return: " + str(ret))
logger.info("exit: vertexSetToDataFrame")

return ret
return ret
80 changes: 73 additions & 7 deletions pyTigerGraph/pytgasync/pyTigerGraphVertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,84 @@ async def getVertexAttrs(self, vertexType: str) -> list:
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

et = await self.getVertexType(vertexType)
vt = await self.getVertexType(vertexType)
ret = []

for at in et["Attributes"]:
ret.append(
(at["AttributeName"], self._getAttrType(at["AttributeType"])))
if "Attributes" in vt:
for at in vt["Attributes"]:
at["AttributeType"]["AttributeType"] = at["AttributeType"].pop("Name")
ret.append(
(at["AttributeName"], at["AttributeType"])
)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getAttributes")

return ret

async def getVertexVectors(self, vertexType: str) -> list:
"""Returns the names and types of the embedding attributes of the vertex type.

Args:
vertexType:
The name of the vertex type.

Returns:
A list of (vector_name, vector_type) tuples.
The format of vector_type is one of
- "scalar_type"
- "complex_type(scalar_type)"
- "map_type(key_type,value_type)"
and it is a string.
"""
logger.info("entry: getVertexVectors")
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

vt = await self.getVertexType(vertexType)
ret = []

if "EmbeddingAttributes" in vt:
for et in vt["EmbeddingAttributes"]:
ret.append(
(et["Name"], et)
)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getVertexVectors")

return ret

async def getVectorStatus(self, vertexType: str, vectorName: str = "") -> bool:
"""Check the rebuild status of the vertex type or the embedding attribute

Args:
vertexType:
The name of the vertex type.
vectorAttr:
The name of the vector attribute, optional.

Returns:
a bool indicates whether vector rebuild is done or not

Endpoint:
- `GET /vector/status/{graph_name}/{vertex_type}/[{vector_name}]`
"""
logger.info("entry: getVectorStatus")
if logger.level == logging.DEBUG:
logger.debug("params: " + self._locals(locals()))

ret = await self._req("GET", self.restppUrl + "/vector/status/" +
self.graphname + "/" + vertexType + "/" + vectorName)

if logger.level == logging.DEBUG:
logger.debug("return: " + str(ret))
logger.info("exit: getVectorStatus")

return len(ret["NeedRebuildServers"]) == 0

async def getVertexType(self, vertexType: str, force: bool = False) -> dict:
"""Returns the details of the specified vertex type.

Expand Down Expand Up @@ -222,7 +287,7 @@ async def upsertVertex(self, vertexType: str, vertexId: str, attributes: dict =
```
Example:
```
{"name": "Thorin", points: (10, "+"), "bestScore": (67, "max")}
{"name": "Thorin", points: (10, "+"), "bestScore": (83, "max"), "embedding": [0.1, -0.2, 3.1e-2]}
```
For valid values of `<operator>` see xref:tigergraph-server:API:built-in-endpoints.adoc#_operation_codes[Operation codes].

Expand Down Expand Up @@ -275,7 +340,8 @@ async def upsertVertices(self, vertexType: str, vertices: list, atomic: bool = F
----
[
(2, {"name": "Balin", "points": (10, "+"), "bestScore": (67, "max")}),
(3, {"name": "Dwalin", "points": (7, "+"), "bestScore": (35, "max")})
(3, {"name": "Dwalin", "points": (7, "+"), "bestScore": (35, "max")}),
(4, {"name": "Thorin", points: (10, "+"), "bestScore": (83, "max"), "embedding": [0.1, -0.2, 3.1e-2]})
]
----

Expand Down Expand Up @@ -810,4 +876,4 @@ async def vertexSetToDataFrame(self, vertexSet: dict, withId: bool = True, withT
logger.debug("return: " + str(ret))
logger.info("exit: vertexSetToDataFrame")

return ret
return ret