数据类型
Ultipa 属性与 Python 数据类型的对应关系:
Ultipa | Python |
---|---|
string | string |
text | string |
float | float |
double | float |
int32 | int |
uint32 | int |
int64 | int |
uint64 | int |
datetime | string |
timestamp | string 或 int |
InsertNodesBatchBySchema()
InsertNodesBatchBySchema()
可以为某一个点 schema 导入多条数据,需保证数据携带的属性与声明 schema 时携带的属性一致。
方法及相关类:
def InsertNodesBatchBySchema(self,
schema: ULTIPA_REQUEST.Schema,
rows: List[ULTIPA.Node],
config: ULTIPA_REQUEST.InsertConfig
) -> ULTIPA_RESPONSE.InsertResponse
class Schema:
def __init__(self,
name: str,
properties: List[Property],
desc: str = None,
type: str = None,
DBType: ULTIPA.DBType = None,
total: int = None
)
class Property:
def __init__(self, name: str, type: ULTIPA.PropertyType = None, desc: str = None)
class Node:
def __init__(self, values: Dict, schema: str = None, id: str = None, uuid: int = None)
示例:为图集 test 的点 schema 'customer' 插入多条数据,采用插入模式
from ultipa import Connection, UltipaConfig, InsertConfig
from ultipa import ULTIPA_REQUEST, ULTIPA
# 创建名为 conn 的连接并使用 default 图集,此部分代码省略
schema = ULTIPA_REQUEST.Schema(
"customer",
[
ULTIPA_REQUEST.Property("name", ULTIPA.PropertyType.PROPERTY_STRING),
ULTIPA_REQUEST.Property("level", ULTIPA.PropertyType.PROPERTY_INT32)
]
)
rows = [
ULTIPA.Node(values = {"name": "Paal", "level": 2}),
ULTIPA.Node(values = {"name": "Alice", "level": 1})
]
req = conn.InsertNodesBatchBySchema(
schema,
rows,
InsertConfig(ULTIPA.InsertType.NORMAL, "test")
)
req.Print()
InsertNodesBatchAuto()
InsertNodesBatchAuto()
可以同时为多个点 schema 导入多条数据,需保证数据携带 schema,且携带的属性与图集中该 schema 的属性一致。
方法及相关类:
def InsertNodesBatchAuto(self,
nodes: List[ULTIPA.Node],
config: ULTIPA_REQUEST.InsertConfig
) -> ULTIPA_RESPONSE.ResponseBatchAutoInsert
class Node:
def __init__(self, values: Dict, schema: str = None, id: str = None, uuid: int = None)
示例:为图集 test 的多个点 schema 插入多条数据,采用插入更新模式
from ultipa import Connection, UltipaConfig, InsertConfig
from ultipa import ULTIPA_REQUEST, ULTIPA
# 创建名为 conn 的连接并使用 default 图集,此部分代码省略
rows = [
ULTIPA.Node(values = {"name": "Paal", "level": 3}, schema = "customer", id = "CUST000A2D"),
ULTIPA.Node(values = {"balance": 4000.0, "level": 1}, schema = "card", id = "CARD000901")
]
req = conn.InsertNodesBatchAuto(
rows,
InsertConfig(ULTIPA.InsertType.UPSERT,"test")
)
req.Print()
InsertEdgesBatchBySchema()
InsertEdgesBatchBySchema()
可以为某一个边 schema 导入多条数据,需保证数据携带的属性与声明 schema 时携带的属性一致。
方法及相关类:
def InsertEdgesBatchBySchema(self,
schema: ULTIPA_REQUEST.Schema,
rows: List[ULTIPA.Edge],
config: ULTIPA_REQUEST.InsertConfig
) -> ULTIPA_RESPONSE.InsertResponse
class Schema:
def __init__(self,
name: str,
properties: List[Property],
desc: str = None,
type: str = None,
DBType: ULTIPA.DBType = None,
total: int = None
)
class Property:
def __init__(self, name: str, type: ULTIPA.PropertyType = None, desc: str = None)
class Edge:
def __init__(self,
values: Dict,
from_id: str = None,
from_uuid: int = None,
to_id: str = None,
to_uuid: int = None,
schema: str = None,
uuid: int = None
)
示例:为图集 test 的边 schema 'transfer' 插入多条数据,采用插入模式
from ultipa import Connection, UltipaConfig, InsertConfig
from ultipa import ULTIPA_REQUEST, ULTIPA
# 创建名为 conn 的连接并使用 default 图集,此部分代码省略
schema = ULTIPA_REQUEST.Schema(
"transfer",
[
ULTIPA_REQUEST.Property("amount", ULTIPA.PropertyType.PROPERTY_FLOAT),
ULTIPA_REQUEST.Property("type", ULTIPA.PropertyType.PROPERTY_STRING)
]
)
rows = [
ULTIPA.Edge(values = {"amount": 2000.0, "type": "I"}, from_id = "CARD000901", to_id = "CARD000A21"),
ULTIPA.Edge(values = {"amount": 125.5, "type": "II"}, from_id = "CARD000BB2", to_id = "CARD000C74")
]
req = conn.InsertEdgesBatchBySchema(
schema,
rows,
InsertConfig(ULTIPA.InsertType.NORMAL,"test")
)
req.Print()
InsertEdgesBatchAuto()
InsertEdgesBatchAuto()
可以同时为多个边 schema 导入多条数据,需保证数据携带 schema,且携带的属性与图集中该 schema 的属性一致。
方法及相关类:
def InsertEdgesBatchAuto(self,
edges: List[ULTIPA.Edge],
config: ULTIPA_REQUEST.InsertConfig
) -> ULTIPA_RESPONSE.ResponseBatchAutoInsert
class Edge:
def __init__(self,
values: Dict,
from_id: str = None,
from_uuid: int = None,
to_id: str = None,
to_uuid: int = None,
schema: str = None,
uuid: int = None
)
示例:为图集 test 的多个边 schema 插入多条数据,采用插入覆盖模式
from ultipa import Connection, UltipaConfig, InsertConfig
from ultipa import ULTIPA_REQUEST, ULTIPA
# 创建名为 conn 的连接并使用 default 图集,此部分代码省略
rows = [
ULTIPA.Edge(values = {"amount": 2000.0, "type": "IV"}, from_id = "CARD000901", to_id = "CARD000A21", schema = "transfer", uuid = 5),
ULTIPA.Edge(values = {}, from_id = "STAF000E32", to_id = "CUST000F9A", schema = "manage", uuid = 7)
]
req = conn.InsertEdgesBatchAuto(
rows,
InsertConfig(ULTIPA.InsertType.OVERWRITE,"test")
)
req.Print()