概述
属性与schema关联,用来描述点和边的不同特征。例如,点schemacard
可能有属性balance
和openedDate
,边schematransfers
可能有属性amount
和time
。
UQL使用运算符.
提取schema中的属性。使用表达式@<schema>.<property>
指定schema下的属性,如@company.name
。
系统属性
每个点携带两条系统属性_id
和_uuid
,是点数据的唯一标识符。点的_id
值可以手动指定,但需确保该值唯一,而_uuid
值由系统自动生成。
系统属性 |
值类型 | 描述 |
---|---|---|
_id |
string |
点的字符串类型(最大长度为128字节)唯一标识符 |
_uuid |
uint64 |
点的数值型唯一标识符 |
每条边仅携带一条系统属性_uuid
,是边数据的唯一标识符,由系统自动生成。每条边连接一个起点和一个终点,_from
/_to
和_from_uuid
/_to_uuid
可用来显示边的两个端点。
系统属性 |
值类型 | 描述 |
---|---|---|
_uuid |
uint64 |
边的数值型唯一标识符 |
_from |
string |
边起点的_id |
_to |
string |
边终点的_id |
_from_uuid |
uint64 |
边起点的_uuid |
_to_uuid |
uint64 |
边终点的_uuid |
显示属性
获取当前图集中所有属性信息:
// 显示所有属性
show().property()
// 显示所有点属性
show().node_property()
// 显示与指定点schema关联的属性
show().node_property(@card)
// 显示所有边属性
show().edge_property()
// 显示与指定边schema关联的属性
show().edge_property(@transfers)
属性信息展示在不同表格中:
- 点属性:表
_nodeProperty
展示所有点属性信息,表_nodeProperty_shard_N
展示分区N
中的点属性信息。 - 边属性:表
_edgeProperty
展示所有边属性信息,表_edgeProperty_shard_N
展示分区N
中的边属性信息。
表中各字段提供了每个属性的基础信息:
字段 |
描述 |
---|---|
name |
属性名 |
type |
属性值类型 |
lte |
属性是否已加载至分片内存以加速查询 |
read |
当前数据库用户能否读取该属性,1 表示可以,0 表示不可以 |
write |
当前数据库用户能否写入该属性,1 表示可以,0 表示不可以 |
schema |
属性关联的schema |
description |
对属性的描述 |
encrypt |
属性加密方法 |
创建属性
使用单个create()
语句创建一或多个属性。串联使用node_property()
或edge_property()
方法可指定每个属性。使用encrypt()
方法可以加密属性。
create()
.node_property(<schema>, "<propName>", <propValueType?>, "<propDesc?>").encrypt("<encMeth?>")
.edge_property(<schema>, "<propName>", <propValueType?>, "<propDesc?>").encrypt("<encMeth?>")
...
方法 | 参数 | 描述 |
---|---|---|
node_property() 或edge_property() |
<schema> |
指定点schema或边schema,如@user ;@* 指代所有点schema或边schema |
<propName> |
属性名称。命名规范如下:
|
|
<propValueType?> |
可选。属性值类型。忽略该参数时,将默认使用string 。查看所有属性值类型。请注意,属性创建完成后,无法更改其值类型 |
|
<propDesc?> |
可选。对属性的描述 | |
encrypt() |
<encMeth?> |
可选。加密属性,支持使用以下方法:AES128 (默认),AES256 ,RSA 和ECC |
整数类属性
整数类属性值类型包括int32
,uint32
,int64
和uint64
。
create().node_property(@user, "age", uint32)
小数类属性
小数类属性值类型包括float
,double
和decimal
。
create()
.edge_property(@links, "distance", float)
.edge_property(@links, "weight", "decimal(25,10)", "Weight of the relation")
decimal(25,10)
指定一个精度(所有数字的位数,不包括小数点)为25、标度(小数点后的数字位数)为10的decimal
类型。可设置的精度范围为1~65,标度范围为0~30。特别注意,声明decimal属性值类型时,需使用一对引号包裹decimal(<precision>, <scale>)
。
文本类属性
文本类属性值类型包括string
和text
,其中string
是默认类型,可以不明确指定。
create()
.node_property(@post, "title")
.node_property(@post, "content", text)
时间类属性
时间类属性值类型包括datetime
和timestamp
。
create()
.node_property(@post, "createdOn", timestamp, "When the post is created")
.node_property(@post, "publishedOn", datetime, "When the post is published")
布尔类属性
布尔类属性值类型为bool
。
create().node_property(@city, "isCapital", bool, "Indicates whether it is the capital city")
空间类属性
空间类属性值类型为point
。
create().node_property(@city, "position", point, "Location of the city")
列表类属性
列表类属性值类型包括子类型int32
、int64
、uint32
、uint64
、float
、double
、string
、text
、datetime
和timestamp
。
create().node_property(@user, "interests", "string[]", "user interest tags")
特别注意,声明列表类属性值类型时,需使用一对引号包裹<subtype>[]
。
集合类属性
集合类属性值类型包括子类型int32
、int64
、uint32
、uint64
、float
、double
、string
、text
、datetime
和timestamp
。
create()
.node_property(@user, "heights", "set(float)", "Store user heights history as a set")
特别注意,声明集合类属性值类型时,需使用一对引号包裹set(<subtype>)
。
为所有schema创建一个属性
为所有边schema创建属性time
:
create().edge_property(@*, "time", datetime)
加密属性
创建属性password
并使用AES256
方法对其加密:
create().node_property(@user, "password", string).encrypt("AES256")
修改属性名称和描述
使用语句alter().node_property().set()
或alter().edge_property().set()
修改属性的名称和描述。
在node_property()
或edge_property()
方法里,可使用@<schema>.<property>
格式指定某属性,或使用@*.<property>
格式指定所有同名属性。
修改点属性@user.name
的名称和描述:
alter().node_property(@user.name).set({name: "Name", description: "Full name"})
修改所有名为time
的边属性的名称:
alter().edge_property(@*.time).set({name: "createdOn"})
删除属性
使用单个drop()
语句可以删除一或多个属性。串联使用node_property()
或edge_property()
方法可指定每个属性。属性删除后,所有相关数据都将删除,其中包括属性值、关联的索引、全文索引和内存中加载到引擎的值。
在node_property()
或edge_property()
方法中,可使用@<schema>.<property>
格式指定某个属性。
删除点属性@user.name
:
drop().node_property(@user.name)
删除边属性time
:
drop().edge_property(@*.time)
删除多个属性:
drop().node_property(@user.age).edge_property(@*.time)