Vertex Documentation¶
get_vertex_id_by_pk¶
查询点id。根据点pk查询点id。 该方法不限定点类型,将去所有点类型中查询是否有点pk存在,返回点id集合。
函数声明
def get_vertex_id_by_pk(self, pk: str) -> Set[int]
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
响应参数
Parameter |
Type |
DESC |
Set[int] |
点id集合 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk为空时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
#查询主键为"1374813"的点集
print(graph.get_vertex_id_by_pk('1374813'))
get_vertex_id_by_pk_and_type¶
查询点id。根据点pk和类型获取点id。 在一个确定的点类型下,点pk和点id是一一对应的。
函数声明
def get_vertex_id_by_pk_and_type(self, pk: str, type: str) -> int
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
响应参数
Parameter |
Type |
DESC |
int |
点id |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk为空时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
#查询"个人"类型下主键为"1374813"的点
print(graph.get_vertex_id_by_pk_and_type("1374813", "个人"))
retrieve_vertex¶
查询点。根据点id查询点信息。
函数声明
def retrieve_vertex(self, id: int) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
id |
Y |
int |
点id,不能小于0。 |
响应参数
Parameter |
Type |
DESC |
查询的点信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点id小于0时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
#from graphdbapi.types.graph import Vertex
#查询点id为100的点的详细信息
vertex = graph.retrieve_vertex(100)
print(vertex)
retrieve_vertex_by_pk¶
查询点。根据点pk和type查询点。 在一个确定的点类型下,根据点pk仅能查询到一个点。
函数声明
def retrieve_vertex_by_pk(self, pk: str, type: str) -> Vertex:
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
响应参数
Parameter |
Type |
DESC |
查询的点信息 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.types.graph import Vertex
#查询"个人"类型下主键为"1374813"的点的详细信息
vertex = graph.retrieve_vertex_by_pk('1374813", "个人"')
print(vertex)
retrieve_vertexes_by_type¶
查询点类型下的所有点。迭代获取某个点类型的所有点信息。
函数声明
def retrieve_vertexes_by_type(self, type: str) -> Iterator[Vertex]
参数说明
Parameter |
Optional |
Type |
DESC |
type |
Y |
str |
点类型,不能为空。 |
响应参数
Parameter |
Type |
DESC |
Iterator[Vertex] |
点信息迭代器。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当type为空时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
#from graphdbapi.types.graph import Vertex
#获取所有的person点
for person in graph.retrieve_vertexes_by_type("person"):
print(person)
retrieve_vertexes¶
批量查询点。通过点id查询点信息。如果不存在,则会返回异常。 结果按传入顺序构成集合,集合中包含查询的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def retrieve_vertexes(self, ids: List[int]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
ids |
Y |
List[int] |
点id列表,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含查询的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确。当参数集合为空,以及集合中存在None、点id格式不正确时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.v1.graph import ResponseItem
for res in graph.retrieve_vertexes([0,1,2,3]):
print(res)
retrieve_vertexes_by_pk¶
批量查询点。通过点pk和type查询点信息。如果不存在,则会返回异常。 结果按传入顺序构成集合,集合中包含查询的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def retrieve_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
点信息列表,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
查询点列表的结果信息,包含添加成功的点详细信息和添加失败的异常信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点列表为空或者其中的id或pk和type为None时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.v1.graph import ResponseItem
from graphdbapi.v1.graph.VertexInfoByPk import VertexInfoByPk
infos = [
VertexInfoByPk.init_vertex_info_by_pk("101", "person"),
VertexInfoByPk.init_vertex_info_by_pk("102", "person"),
VertexInfoByPk.init_vertex_info_by_pk("1031", "person"),
]
for res in graph.retrieve_vertexes_by_pk(infos):
print(res)
update_vertexes¶
批量更新点。通过点id更新点。 结果按传入顺序构成集合,集合中包含更新后的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def update_vertexes(self, items: List[VertexInfoById]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoById] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含更新后的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当list参数中某项为None、id值为空或property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.v1.graph import ResponseItem
from graphdbapi.v1.graph.VertexInfoById import VertexInfoById
infos = [
VertexInfoById.init_vertex_info_by_id(0, {"属性1": "1000"}),
VertexInfoById.init_vertex_info_by_id(1, {"属性1": "1001"}),
VertexInfoById.init_vertex_info_by_id(2, {"属性1": "1002"}),
]
for res in graph.update_vertexes(infos):
print(res)
retrieve_all_vertexes¶
查询所有点。迭代获取数据库中的所有点信息。
函数声明
def retrieve_all_vertexes(self) -> Iterator[Vertex]
响应参数
Parameter |
Type |
DESC |
Iterator[Vertex] |
点信息迭代器 |
异常
Type |
DESC |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.types.graph import Vertex
# 查询所有点
for vertex in graph.retrieve_all_vertexes():
print(vertex)
get_vertex_count¶
查询点个数。查询传入类型去查找点总数。
函数声明
def get_vertex_count(self, type: str) -> int
参数说明
Parameter |
Optional |
Type |
DESC |
type |
Y |
str |
点类型,不能为空。 |
响应参数
Parameter |
Type |
DESC |
int |
点个数 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当类型为空时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# 获取person点的总数
print(graph.get_vertex_count("person"))
get_all_vertex_count¶
查询点个数。查询图中点总数。
函数声明
def get_all_vertex_count(self) -> int
响应参数
Parameter |
Type |
DESC |
int |
点个数 |
异常
Type |
DESC |
DatabaseException |
数据库内部异常。 |
示例
print(graph.get_all_vertex_count())
get_degree¶
查询点的degree信息。
函数声明
def get_degree(
self, id: int, edge_type_filter: Union[Set[str], None], direction: Direction,
vertex_condition: Union[VisitCondition, None], edge_condition: Union[VisitCondition, None],
include_loop: bool
) -> EdgeDegreeInfo
参数说明
Parameter |
Optional |
Type |
DESC |
id |
Y |
int |
点id,不能小于0。 |
edge_type_filter |
N |
Set[str] |
边类型的过滤条件。只会返回满足参数中边类型的边。填None不参与计算。建议类型过滤使用这个字段,而不是edge_condition |
direction |
Y |
边方向,不能为None。 |
|
vertex_condition |
N |
点条件,填None不参与计算 |
|
edge_condition |
N |
边条件,填None不参与计算 |
|
include_loop |
Y |
bool |
True计算自环,False不计算自环 |
响应参数
Parameter |
Type |
DESC |
点的degree信息 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点id小于0、查询方向为None时将抛出异常。 |
VertexNotFoundException |
点在图中不存在时将抛出异常。 |
TypeNotFoundException |
边类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
点/边条件过滤对应的属性类型在指定点/边类型中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph.query.condition.PropertyFilter import PropertyFilter
from graphdbapi.v1.graph.query.condition.VisitConditionByProperty import VisitConditionByProperty
from graphdbapi.v1.enum import Direction, QueryMethod
from graphdbapi.v1.graph.query import EdgeDegreeInfo
# 保留person_to_phone,person_to_address,person_to_person三种边类型
edge_type_filter = {"person_to_phone", "person_to_address", "person_to_person"}
direction = Direction.BOTH
# 点过滤条件
# person类型下age大于18的点
vertex_property_filter = PropertyFilter.init_Property_filter()
vertex_property_filter.add_filter_by_params("age", QueryMethod.More, 18)
vertex_condition = VisitConditionByProperty.init_visit_condition_by_property({"person": vertex_property_filter}, True)
# 边过滤条件
edge_condition = None
#在考虑自环的情况下,筛选age大于18的person点,并且过滤person_to_phone,person_to_address,person_to_person三种边类型
print(graph.get_degree(0, edge_type_filter, direction, vertex_condition, edge_condition, True))
insert_vertex_by_pk¶
新增点。通过点pk和type新增一个点,属性为可选项。
函数声明
def insert_vertex_by_pk(self, pk: str, type: str, property: Dict[str, Any] = None) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
property |
N |
Dict[str, Any] |
点属性。填None或{}时,表示添加的点没有属性值。 |
响应参数
Parameter |
Type |
DESC |
新增点的信息 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空、property输入的属性类型不支持时将抛出异常。 |
VertexFoundException |
点已经存在时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
属性名在点类型中没有定义时将抛出异常。 |
ValueFormatException |
属性值类型错误时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# from graphdbapi.types.graph import Vertex
# 添加主键为"10000",age为18的person点
print(graph.insert_vertex_by_pk("10000", "person", {"age": 18}))
insert_batch_vertex_by_pk¶
批量新增点。通过点pk和type新增点,属性为可选项。
函数声明
def insert_batch_vertex_by_pk(self, items: List[VertexInfoByPk]) -> None:
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
示例
import time
from graphdbapi.v1.graph import VertexInfoByPk
infos = [
VertexInfoByPk.init_vertex_info_by_pk(str(time.time_ns() + 1000), "test"),
VertexInfoByPk.init_vertex_info_by_pk(str(time.time_ns() + 2000), "test"),
VertexInfoByPk.init_vertex_info_by_pk(str(time.time_ns() + 3000), "test"),
]
graph.insert_batch_vertex_by_pk(infos)
for info in infos:
print(graph.retrieve_vertex_by_pk(info.get_pk(), info.get_type()))
insert_vertexes_by_pk¶
批量新增点。通过点pk和type新增点,属性为可选项。 结果按传入顺序构成集合,集合中包含新增后的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def insert_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含新增后的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当list为空,参数中某项为None、pk或type值为空或property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
#
from graphdbapi.v1.graph import VertexInfoByPk,ResponseItem
infos = [
VertexInfoByPk.init_vertex_info_by_pk("1002", "person"),
VertexInfoByPk.init_vertex_info_by_pk("1003", "person"),
VertexInfoByPk.init_vertex_info_by_pk_and_property("1004", "person",{"age":20}),
]
result = graph.insert_vertexes_by_pk(infos)
print(result)
delete_vertexes¶
批量删除点。通过点id删除点。如果点不存在或删除失败,则会返回异常结果集。 结果按传入顺序构成集合,集合中包含成功信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def delete_vertexes(self, ids: List[int]) -> List[str]:
参数说明
Parameter |
Optional |
Type |
DESC |
ids |
Y |
List[int] |
点id列表,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[str] |
批量操作结果集。点删除成功时返回None,点删除失败时返回错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点列表为空或者其中的id为None时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
infos = [
0,123,456,789
]
print(graph.delete_vertexes(infos))
delete_vertex¶
删除点。根据点id删除点。
函数声明
def delete_vertex(self, id: int) -> None
参数说明
Parameter |
Optional |
Type |
DESC |
id |
Y |
int |
点id,不能小于0。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点id小于0时将抛出异常。 |
VertexNotFoundException |
点在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# 删除点id为0的点
graph.delete_vertex(0)
delete_vertex_by_pk¶
删除点。通过点pk和type删除点。
函数声明
def delete_vertex_by_pk(self, pk: str, type: str) -> None
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
VertexNotFoundException |
点在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# 删除主键为"1002",类型为person的点
graph.delete_vertex_by_pk("1002", "person")
update_vertex_by_pk¶
更新点。通过点pk和type更新点。如果已存在,则会比较属性值。
函数声明
def update_vertex_by_pk(self, pk: str, type: str, property: Dict[str, Any], is_merge:bool) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
property |
Y |
Dict[str, Any] |
点属性。 |
is_merge |
Y |
bool |
为true时集合属性追加,为fasle属性覆盖 |
响应参数
Parameter |
Type |
DESC |
点的详细信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空、property为空、property输入的属性类型不支持时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
属性名在点类型中没有定义时将抛出异常。 |
ValueFormatException |
属性值类型错误时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.types.graph import Vertex
pk = "4730"
type = "person"
property = dict();
property['age'] = '30'
property['sex'] = '女'
# 更新person类型主键为'4730'的点的属性
print(graph.update_vertex_by_pk(pk, type, property, True))
update_vertex¶
更新点。通过点id更新点属性。
函数声明
def update_vertex(self, id: int, property: Dict[str, Any], is_merge: bool) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
id |
Y |
int |
点id,不能小于0。 |
property |
Y |
Dict[str, Any] |
点属性 |
is_merge |
Y |
bool |
为true时集合属性追加,为fasle属性覆盖 |
响应参数
Parameter |
Type |
DESC |
更新后的点信息 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点id小于0、property输入的属性类型不支持时将抛出异常。 |
VertexNotFoundException |
点在图中不存在时将抛出异常。 |
PropertyNotFoundException |
属性名在点类型中没有定义时将抛出异常。 |
ValueFormatException |
属性值类型错误时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.types.graph import Vertex
id = 0
property = dict()
property['age'] = '30'
property['sex'] = '女'
# 更新id为0的点的属性
print(graph.update_vertex(id, property, True))
delete_vertexes_by_pk¶
批量删除点。通过点pk和type删除点。如果不存在或删除失败,则会返回异常结果集。 结果按传入顺序构成集合,集合中包含成功信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def delete_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[str]:
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[str] |
批量操作结果集。点删除成功时返回None,点删除失败时返回错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确。当参数集合为空,以及集合中存在None、pk和type不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph import VertexInfoByPk
infos = [
VertexInfoByPk.init_vertex_info_by_pk("1002", "person"),
VertexInfoByPk.init_vertex_info_by_pk("1002", "person"),
VertexInfoByPk.init_vertex_info_by_pk("1003", "person"),
]
# 删除主键为"1002",person类型与主键为"1003",person类型的点
print(graph.delete_vertexes_by_pk(infos))
update_vertexes_by_pk¶
更新点。通过点pk和type更新点。 结果按传入顺序构成集合,集合中包含更新后的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def update_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含更新后的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当参数为空,参数中某项为None、pk或type值为空或property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph import VertexInfoByPk,ResponseItem
infos = [
VertexInfoByPk.init_vertex_info_by_pk("1002", "person",{"age":1}),
VertexInfoByPk.init_vertex_info_by_pk("1003", "person",{"age":20}),
]
# 添加点,并打印结果
print(graph.update_vertexes_by_pk(infos))
search_vertexes_by_index¶
通过索引,查找点数据, 返回点id迭代器,所查询的点属性必须存在索引
函数声明
def search_vertexes_by_index(self, type_name: str, prop_name: str, data: Any, skip: int, limit: int) -> Iterator[int]
参数说明
Parameter |
Optional |
Type |
DESC |
type_name |
Y |
str |
类型名 |
prop_name |
Y |
str |
属性名 |
data |
Y |
Any |
所查找的值 |
skip |
Y |
int |
跳过条目 |
limit |
Y |
int |
限制返回数量 |
响应参数
Parameter |
Type |
DESC |
Iterator[int] |
点id迭代器 |
异常
Type |
DESC |
ParamException |
参数格式不正确时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
# 查询20个年龄为18的user点,并返回点id的迭代器
print(list(graph.search_vertexes_by_index("user", "age", 18, 0, 20)))
upsert_vertex_by_pk¶
新增或更新点。通过点pk和type新增或更新点。如果已存在,则会比较属性值。
函数声明
def upsert_vertex_by_pk(self, pk: str, type: str, property: Dict[str, Any]) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
property |
Y |
Dict[str, Any] |
点属性。 |
响应参数
Parameter |
Type |
DESC |
点的详细信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空、property为空、property输入的属性类型不支持时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
属性名在点类型中没有定义时将抛出异常。 |
ValueFormatException |
属性值类型错误时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
pk = "4730"
type = "person"
property = dict();
property['age'] = '30'
property['sex'] = '女'
# 更新person类型主键为'4730'的点的属性
print(graph.upsert_vertex_by_pk(pk, type, property))
upsert_vertexes_by_pk¶
批量新增或更新点。通过点pk和type新增或更新点。如果已存在,则会比较属性值。 结果按传入顺序构成集合,集合中包含新增或更新后的点信息和错误信息。通过{ResponseItem#is_error()}方法判断操作是否失败。
函数声明
def upsert_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含新增或更新后的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当参数为空,参数中某项为None、pk或type值为空或property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
infos = [
VertexInfoByPk.init_vertex_info_by_pk("1002", "person",{"age":1}),
VertexInfoByPk.init_vertex_info_by_pk("1003", "person",{"age":20}),
]
# 添加点,并打印结果
print(graph.upsert_vertexes_by_pk(infos))
retrieve_or_insert_vertex_by_pk¶
查询或新增点。通过点pk和type查询或新增点。若点已经存在,仅查询并返回点信息,属性值不做修改。若点不存在,新增并返回点信息。
函数声明
def retrieve_or_insert_vertex_by_pk(self, pk: str, type: str, property: Union[Dict[str, Any], None]) -> Vertex
参数说明
Parameter |
Optional |
Type |
DESC |
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
property |
Y |
Dict[str, Any], None |
点属性。填None或{}时,表示添加的点没有属性值。 |
响应参数
Parameter |
Type |
DESC |
点的详细信息 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当pk或type为空、property输入的属性类型不支持时将抛出异常。 |
TypeNotFoundException |
点类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
属性名在点类型中没有定义时将抛出异常。 |
ValueFormatException |
属性值类型错误时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
vertex = graph.retrieve_or_insert_vertex_by_pk("111111", 'person', None)
print(vertex)
retrieve_or_insert_vertexes_by_pk¶
函数声明
def retrieve_or_insert_vertexes_by_pk(self, items: List[VertexInfoByPk]) -> List[ResponseItem]
参数说明
Parameter |
Optional |
Type |
DESC |
items |
Y |
List[VertexInfoByPk] |
参数集合,不能为空。 |
响应参数
Parameter |
Type |
DESC |
List[ResponseItem] |
批量操作结果集。包含查询或新增后的点信息和错误信息。 |
异常
Type |
DESC |
ParamException |
参数格式不正确。当参数集合为空,以及集合中存在None、pk或type为空、property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
infos = [
VertexInfoByPk.init_vertex_info_by_pk("1002", "person",{"age":18}),
VertexInfoByPk.init_vertex_info_by_pk("1002", "person",{"age":1}),
VertexInfoByPk.init_vertex_info_by_pk("1003", "person",{"age":20}),
]
# 添加/更新点,并打印结果
print(graph.retrieve_or_insert_vertexes_by_pk(infos))
search_vertex_property¶
通过类型、属性查询点。
函数声明
def search_vertex_property(self, vertex_type: str, predicates: List[SearchPredicate], orders: List[SearchOrder],
skip: int, limit: int) -> Iterator[Vertex]:
参数说明
Parameter |
Optional |
Type |
DESC |
vertex_type |
Y |
str |
点类型名,不能为空。 |
predicates |
Y |
List[SearchPredicate] |
查询谓词,每个谓词包括:属性名、查询值 |
orders |
Y |
List[SearchOrder] |
属性排序 |
skip |
Y |
int |
跳过 |
limit |
Y |
int |
限制返回数量 |
响应参数
Parameter |
Type |
DESC |
Iterator[Vertex] |
结果点迭代器。 |
异常
Type |
DESC |
ParamException |
参数格式不正确。当参数集合为空,以及集合中存在None、pk或type为空、property输入的属性类型不支持时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1 import SearchPredicate, SearchOrder
from graphdbapi.v1.enum import OrderBy, SearchType
# 查询图中所有姓李的人物,并按年龄降序排列
for _ in graph.search_vertex_property(
"user", [SearchPredicate.init_by_value(SearchType.Suffix, "name", "李")],
[SearchOrder("age", OrderBy.DESC)], -1, -1):
print(_)