Skip to content

Components

BaseComponent

BaseComponent()

Source: hetu/data/component.py:115

所有组件的基类

Attributes

  • dtypes (np.dtype) — 组件的numpy格式的dtype信息

Methods

new_row

new_row(id_=None) -> numpy.record

Source: hetu/data/component.py:225

返回空数据行,id请设置为None,会自动生成规范雪花uuid,用于insert

new_rows

new_rows(size) -> numpy.rec.recarray

Source: hetu/data/component.py:235

返回多行空数据行,用于批量insert

str_max_len

str_max_len(prop_name: str) -> int

Source: hetu/data/component.py:245

返回字符串属性可存储的最大字符数(由该列 dtype 的列宽推导)。

用途:把可配置的长度上限钳到实际列宽,避免在调用方硬编码列宽,例如 min(user_cfg, MyComp.str_max_len("name"))。仅适用于字符串(U)/ 字节(S)属性;其它 dtype 抛 ValueError。

dict_to_struct

dict_to_struct(data: dict) -> numpy.record

Source: hetu/data/component.py:263

从dict转换为c-struct like的类型,成为可直接传给数据库的行数据

struct_to_dict

struct_to_dict(data: numpy.record) -> dict[str, typing.Any]

Source: hetu/data/component.py:271

从c-struct like的行数据转换为typed dict

duplicate

duplicate(namespace: str, suffix: str) -> type[hetu.data.component.BaseComponent]

Source: hetu/data/component.py:277

复制一个新的副本组件。拥有相同的定义,但使用suffix结尾的新的名字。

注意:只能在 define_system 时,传递成员变量时使用,如:

@hetu.define_system(namespace="Loot", components=(Order.duplicate("Loot", "Copy"),))

get_duplicates

get_duplicates(namespace: str) -> dict[str, type[hetu.data.component.BaseComponent]]

Source: hetu/data/component.py:299

获取此Component在指定namespace下的所有副本实例

is_rls

is_rls() -> bool

Source: hetu/data/component.py:304

判断此Component是否是RLS权限


Permission

Permission(*values)

Source: hetu/common/permission.py:11

Bases: IntEnum

客户端访问权限级别。

用于 define_endpoint / define_system 暴露给客户端的调用权限,也用于 define_component 声明Component数据的读取权限。服务端内部代码不受这些权限 限制;业务逻辑中的写入权限和更细粒度安全检查仍需要自行实现。

Attributes

  • EVERYBODY (Any) — 任何客户端连接都允许访问;适合公开状态、公告、配置等低敏感数据。

  • USER (Any) — 仅已登录客户端允许访问;要求 ctx.caller 有有效用户id。

  • OWNER (Any) — Component行级读取权限;等同于 RLS 且预设 rls_compare=("eq", "owner", "caller")

  • RLS (Any) — Component自定义行级读取权限;具体比较逻辑由 rls_compare 参数定义。

  • ADMIN (Any) — 仅管理员连接允许访问;要求 ctx.is_admin() 返回True。