概述
属性与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展示某个Shard中的点属性信息。
- 边属性:表_edgeProperty展示所有边属性信息,表_edgeProperty_shard_N展示某个Shard中的边属性信息。
表中各字段提供了每个属性的基础信息:
| 字段 | 描述 | 
|---|---|
| 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)
时间类属性
时间类属性值类型包括date、local datetime、local time、zoned datetime、zoned time、timestamp、datetime、duration(year to month)和duration(day to second)。
create()
  .node_property(@post, "createdOn", "local datetime", "When the post is created")
  .node_property(@post, "visibilityPeriod", "duration(year to month)", "When the post is published")
布尔类属性
布尔类属性值类型为bool。
create().node_property(@city, "isCapital", bool, "Indicates whether it is the capital city")
空间类属性
空间类属性值类型为point和point3d。
create().node_property(@city, "position", point, "Location of the city")
记录类属性
记录类属性值类型为record。
create().node_property(@product, "specs", record, "Specifications such as weight, color and warranty")
二进制类属性
二进制类属性值类型为blob。
create().node_property(@user, "avatar", blob, "Avatar image file")
列表类属性
支持的列表类属性值类型为<subType>[],子类型支持除bool外的其他所有属性值类型。
create().node_property(@user, "interests", "string[]", "user interest tags")
集合类属性
支持的集合类属性值类型为set(<subType>),子类型支持除bool外的其他所有属性值类型。
create()
  .node_property(@user, "heights", "set(float)", "Store user heights history as a set")
为所有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)
