概述
属性与schema关联,用来描述schema的不同属性特征。例如,点schema@card
(银行卡)可关联balance(余额)和openedOn(开卡时间)等属性,边schema@transfersTo
(转账)可关联amount(金额)和time(转账时间)等属性。
UQL使用表达式@<schema>.<property>
过滤指定的schema属性,如@company.name
。
系统属性
每个点、边schema都携带系统属性,在schema创建时自动生成,其名称和类型均无法修改;系统属性无法删除。
系统属性 | 数据类型 | 描述 | |
---|---|---|---|
点 | _id |
String,最大长度128字节 | 点的字符串型唯一标识符 |
_uuid |
Uint64 | 点的数值型唯一标识符 | |
边 | _uuid |
Uint64 | 边的数值型唯一标识符 |
_from |
String | 边起点的_id |
|
_to |
String | 边终点的_id |
|
_from_uuid |
Uint64 | 边起点的_uuid |
|
_to_uuid |
Uint64 | 边终点的_uuid |
唯一标识符(UID)
每个点携带_id
和_uuid
两条系统属性,是点数据的唯一标识符。所有点的_id
值均不相同,_uuid
值也不相同。此外,_id
和_uuid
存在一一对应关系。
每条边携带一条系统属性_uuid
,是边数据的唯一标识符。所有边的_uuid
值均不相同。
点的_uuid
可以和边的_uuid
取相同值。
自定义属性
在每个schema中,用户可创建自定义属性,如姓名、类型和时间。更多详细信息,请参考创建属性。
查看属性
// 查看当前图集中所有schema的属性
show().property()
// 查看当前图集中所有点schema的属性
show().node_property()
// 查看当前图集中所有边schema的属性
show().edge_property()
// 查看当前图集中点@user的属性
show().node_property(@user)
// 查看当前图集中边@like的属性
show().edge_property(@like)
结果示例:
_nodeProperty
name |
type |
lte |
read |
write |
schema |
description |
extra | encrypt |
---|---|---|---|---|---|---|---|---|
name | string | true | 1 | 1 | user | {} | AES128 | |
rate | decimal | false | 1 | 1 | user | 平均用户评分 | {"精度":65,"标度":30} |
_edgeProperty
name |
type |
lte |
read |
write |
schema |
description |
extra | encrypt |
---|---|---|---|---|---|---|---|---|
time | timestamp | false | 1 | 0 | like | {} |
返回结果仅包含自定义属性信息;系统属性不在结果中显示。
创建属性
语法
// 在当前图集中为一个指定点schema创建一个属性
create().node_property(@<schema>, "<name>", <type?>, "<desc?>").encrypt()
// 在当前图集中为所有点schema创建一个属性
create().node_property(@*, "<name>", <type?>, "<desc?>").encrypt()
// 在当前图集中为一个指定边schema创建一个属性
create().edge_property(@<schema>, "<name>", <type?>, "<desc?>").encrypt()
// 在当前图集中为所有边schema创建一个属性
create().edge_property(@*, "<name>", <type?>, "<desc?>").encrypt()
// 在当前图集中同时为多个点、边schema创建属性
create()
.node_property(@<schema>, "<name>", <type?>, "<desc?>").encrypt()
.edge_property(@<schema>, "<name>", <type?>, "<desc?>").encrypt()
node_property()
和edge_property()
参数说明:@<schema>
: 指定点或边schema;使用@*
指代所有点或边schema。<name>
: 属性名称。<type?>
: 属性类型;若忽略此参数,默认使用string类型。<desc?>
: 属性描述,为可选项。
- 如需加密属性值,可在方法链中串联
encrypt()
方法:- 使用AES128算法加密属性。
- 目前仅支持加密文本类型(string和text)属性。
命名规则
属性命名规则如下:
- 名称长度为2~64个字符。
- 不能以波浪号
~
开头。 - 不能包含反引号
`
。 - 不能与系统保留字重名。
与同一个schema关联的属性不能重名,但与不同schema关联的属性可以重名。
属性名称含有字母(A-Z,a-z)、数字(0-9)、下划线(_
)以外的字符时,在UQL语句中使用时需要用一对反引号(`
)包裹。
find().nodes({`Last-name` == "White"}) as n
return n
创建Integer类型属性
支持的数据类型包括int32
、uint32
、int64
和uint64
。
create().node_property(@course, "credits", int32, "Credits of the course")
创建Decimal类型属性
支持的数据类型包括float
、double
和decimal
。
create()
.node_property(@record, "score", float, "Score of the record")
.edge_property(@connects, "weight", "decimal(25,10)", "Weight of the relation")
decimal(25,10)
代表一个精度(所有数字的位数)为25,标度(小数点后的数字位数)
为10的小数。用户可设置的精度范围为1~65,标度范围为0~30。
特别注意,在创建decimal类型属性时,需使用一对引号包裹decimal(<precision>, <scale>)
。
创建文本类型属性
支持的数据类型包括string
和text
。
create()
.node_property(@post, "title")
.node_property(@post, "content", text, "Main content of the post").encrypt()
若未指定数据类型,系统默认使用string类型。encrypt()
方法仅支持加密string或text类型。
创建时间类型属性
支持的数据类型包括timestamp
和datetime
。
create()
.node_property(@post, "createdOn", timestamp, "When the post is first created")
.node_property(@post, "publishedOn", datetime, "When the post is published")
创建Point类型属性
支持的数据类型为point
。
create().node_property(@city, "position", point, "City location: latitude and longitude")
创建Blob类型属性
支持的数据类型为blob
。
create()
.node_property(@user, "profileImg", blob, "Store user profile image as binary large object")
创建List类型属性
支持的数据类型包括:int32[]
、int64[]
、uint32[]
、uint64[]
、float[]
、double[]
、string[]
、text[]
、datetime[]
和timestamp[]
。
特别注意,在创建list类型属性时,需使用一对引号包裹<element_type>[]
。
创建Set类型属性
支持的数据类型包括:set(int32)
、set(int64)
、set(uint32)
、set(uint64)
、set(float)
、set(double)
、set(string)
、set(text)
、set(datetime)
和set(timestamp)
。
create()
.node_property(@user, "heights", "set(float)", "Store user heights history as a set")
特别注意,在创建set类型属性时,需使用一对引号包裹set(<element_type>)
。
为所有schema创建一个属性
create().edge_property(@*, "time", datetime)
UQL使用@*
指代所有点schema或边schema,不必指定某个schema的名称。
使用前缀TRY
在当前图集中,同时创建3个边属性,但其中一个属性(time)与已有属性重名。
create()
.edge_property(@default, "weight", int32)
.edge_property(@default, "time", datetime)
.edge_property(@default, "status", string)
属性weight在重名属性之前创建,因此创建成功。而属性status在重名属性之后创建,因此创建失败,并返回报错信息Property exists!
。
TRY create()
.edge_property(@default, "weight", int32)
.edge_property(@default, "time", datetime)
.edge_property(@default, "status", string)
此次属性创建过程同上,但由于使用了前缀TRY
,报错信息被屏蔽,返回信息为SUCCEED
。
修改属性
// 修改当前图集中点属性@user.status的名称和描述
alter().node_property(@user.status).set({name: "Status", description: "Active or Inactive"})
// 修改当前图集中所有点schema的属性status(如有)的名称
alter().node_property(@*.status).set({name: "state"})
// 修改当前图集中边属性@registers.time的名称和描述
alter().node_property(@registers.time)
.set({name: "createdOn", description: "Time for creation"})
// 修改当前图集中所有边schema的属性time(如有)的描述
alter().edge_property(@*.time).set({description: "Time for creation"})
属性一旦创建完成,就无法更改数据类型。
删除属性
删除一个属性的同时会删除与其关联的属性值、内存里LTE的属性以及在硬盘上创建的索引和全文索引。
// 从当前图集中删除点属性@card.branch
drop().node_property(@card.branch)
// 从当前图集中删除所有点schema的属性branch(如有)
drop().node_property(@*.branch)
// 从当前图集中删除边属性@flows.time
drop().edge_property(@flows.time)
// 从当前图集中删除所有边schema的属性time(如有)
drop().edge_property(@*.time)
// 从当前图集中同时删除多个点、边schema的属性
drop()
.node_property(@card.branch)
.edge_property(@*.time)