---
url: /v7.0/cli-reference-data.md
---
# 数据与执行命令

这一页覆盖数据接入、建模、指标、执行和智能能力，和 `hbi-data`、`hbi-data-modeling`、`hbi-pipeline`、`hbi-notebook`、`hbi-data-alert`、`hbi-data-agent` 等 skills 最接近。每个命令域都提供最小可用示例与典型输出，让你第一次就能照着跑。

> \[!TIP] HQL 表达式
> 本页的 `data-model query`、`metric`、`measure` 等命令广泛使用 [HQL (Hengshi Query Language)](https://api.hengshi.com/function_reference.html) 表达式来定义聚合、计算字段和查询条件。HQL 支持聚合函数（SUM、AVG、COUNT 等）、时间函数（YEAR、MONTH、PERIODCOMPARE 等）和条件逻辑。完整的函数列表请参考 [HQL 函数参考](https://api.hengshi.com/function_reference.html)。

> Sense 7.0 **只有自动建模（`modelingType=AUTO`）的数据包支持角色语法**：`{{dataset_id}}[role].{field}`。手工建模（`MANUAL`）及其他场景中的角色没有意义，不应依赖角色区分关联。`role` 为 1–64 个 UTF-16 单元的 Unicode 字母、数字或下划线。角色用于区分同一物理字段的不同数据集角色；它不会要求 CLI 推导角色或规划 join，适用性由服务端验证。

## `connection`

**用途**：管理数据连接、浏览库表、测试连通性。

**常见子命令**：

* 连接本体：`types` `list` `show` `test` `create` `delete` `update`
* 内部授权规则：`auth-rules` `auth-rule-get` `auth-rule-create` `auth-rule-update` `auth-rule-delete`
* 继承控制：`auth-inherit-get` `auth-inherit-update`
* 数据浏览：`browse` `query`

**最小可用示例**：

```bash
hbi connection list --output json
```

**典型输出**：

```json
[
  {
    "id": 39774,
    "title": "analytics-db",
    "accessCount": 273,
    "options": {
      "type": "postgresql",
      "maxConnNum": 10,
      "metaConfig": {
        "dbMajorVersion": 13,
        "dbMinorVersion": 11,
        "dbProductName": "PostgreSQL"
      }
    },
    "createdAt": "2022-10-27 13:54:24",
    "visible": true
  }
]
```

**下一步常见动作**：

* 查看连接详情：`hbi connection show 39774 --output json`
* 测试连通性：`hbi connection test 39774`
* 浏览库表：`hbi connection browse 39774 --output json`

**按 schema/path 浏览**：

```bash
# 只列出 schema/path 层级
hbi connection browse 39774 --schemas --output json

# 精确列出 public schema 下的所有表
hbi connection browse 39774 --schema public --output json

# 多层 path 重复传入 --schema；--query 只在选中的子树内过滤
hbi connection browse 39774 --schema hive --schema default --query orders --output yaml
```

`--schema` 每次接收一个 path 层级，可重复且保留顺序。不要把多层 path 拼成 `catalog.schema`，因为层级名称本身可能包含点号。`--schema` 与 `--query` 同时使用时是 AND 关系；不传 `--schema` 时，`--query` 仍按名称做模糊过滤。

## `dataset`

**用途**：管理数据集、字段、粒度、预览和导入导出。

**常见子命令**：

* 生命周期：`list` `show` `update` `replace` `delete` `duplicate` `import`
* 预览与状态：`preview` `status` `schedule` `lineage` `export`
* 知识增强：`knowledge` `example`
* 创建路径：`create` `create-from-file` `upload` `create-custom-sql` `create-api` `create-reference`
* 数据加工：`create-union` `create-fusion` `create-aggregate` `create-pivot` `create-unpivot`
* 字段与表达式：`fields` `expression-rewrite` `column-create` `column-update` `column-delete`
* 字段补充：`column-values` `column-geo` `column-geo-role` `column-geo-role-reset`
* 粒度：`granularity-list` `granularity-create` `granularity-update` `granularity-delete`

**最小可用示例**：

```bash
hbi dataset list --app 4812 --output json
```

**典型输出**：

```json
[
  {
    "id": 3,
    "title": "销售订单明细",
    "appId": 4812,
    "connectionId": 39774,
    "createdAt": "2025-01-10 09:00:00",
    "updatedAt": "2026-05-20 16:30:00",
    "status": "ready"
  }
]
```

**下一步常见动作**：

* 预览数据：`hbi dataset preview --app 4812 --dataset 3 --limit 10 --output json`
* 查看字段：`hbi dataset fields --app 4812 --dataset 3 --output json`
* 查看数据集状态：`hbi dataset status --app 4812 --dataset 3 --output json`

## `data-model`

**用途**：管理数据模型与联表关系。

### Sense 7.0 AUTO 数据包

先通过 `hbi app show <app_id> --output json` 查看顶层 `modelingType`。缺失或 `null` 的旧响应按 `MANUAL` 处理。MANUAL 模型继续使用关系模型暴露的 relation dataset ID；AUTO 数据包查询所有物理数据集及其字段，使用真实数据集 ID，并排除扩展数据集。

创建图表和指标时，AUTO 数据包可引用包内任意数据集；MANUAL 数据包只能引用已有数据模型的主表和从表。AUTO 的跨数据集关联仍由服务端根据公共维度校验和推导。

AUTO 查询中，裸字段优先匹配 base dataset；若 base 不匹配且其它物理数据集只有一个精确匹配，CLI 使用该物理 ID 限定字段。多个候选时请显式写 `{{dataset_id}}.{field}`。已有的 dataset 或角色限定会保留；服务端验证其作用域。AUTO 不需要也不接受客户端 join 规划，手工 join 写入不适用于该模式。

Data Agent / headless ChatBI 使用同一套 `hbi data-model query`。在 ChatBI 中选择 AUTO 数据包的数据范围时，应选择物理数据集，不选择 `options.type=extend` 的关系数据集；不要用 `context --relation` / `--delta` 扩展手工关系或创建手工 join。`hbi chatbi model-candidates` 在 AUTO 下只列出 `role=physical_dataset` 的候选，候选列表和 dataset `context` 都返回 `modelingType` 与 AUTO `guidance`。按当前会话授权范围分别读取相关物理数据集的 context，再用真实物理 ID 查询；查询、compose 和后续创作都不要手写或覆盖 `datasetIds`，该字段由服务端派生。同包可引用不代表扩大了 delegated scope 或用户权限。

`data-model query --capability --output json` 可用于查看有效建模方式和可用物理引用。服务端连接性错误（包括 `10390` / `10391`）通过既有 API 错误面返回。

**常见子命令**：

* `list` `show` `preview` `query`
* `lineage` `tree`
* `suggest-joins`
* `join-add` `join-list` `join-delete`

**最小可用示例**：

```bash
hbi data-model query --app 4812 --dataset 3 "SUM({amount})" --output json
```

**典型输出**：

```json
{
  "result": [
    {
      "SUM({amount})": 1234567.89
    }
  ],
  "executionTime": 234
}
```

**下一步常见动作**：

* 按维度分组：`hbi data-model query --app 4812 --dataset 3 "SUM({amount})" --by "group({region})" --output json`
* 查看模型树：`hbi data-model tree --app 4812 --dataset 3 --output json`
* 推荐联表：`hbi data-model suggest-joins --app 4812 --dataset 3 --output json`

## `metric`

**用途**：管理原子指标。

**常见子命令**：

* `create` `delete` `update`
* `list` `show`
* `query`

**最小可用示例**：

```bash
hbi metric list --app 4812 --dataset 3 --output json
```

**典型输出**：

```json
[
  {
    "id": 101,
    "name": "销售总额",
    "expression": "SUM({amount})",
    "datasetId": 3,
    "createdAt": "2025-02-10 10:00:00"
  }
]
```

**下一步常见动作**：

* 查看指标详情：`hbi metric show --app 4812 --dataset 3 c1 --output json`
* 查询指标数据：`hbi metric query --app 4812 --dataset 3 c1 --output json`

## `measure`

**用途**：管理业务指标。

**常见子命令**：

* `create` `delete` `update`
* `list` `show`
* `query`

**最小可用示例**：

```bash
hbi measure list --app 4812 --dataset 3 --output json
```

`measure show` 的最后一个参数可以是业务指标的字段名（如 `m1`）或显示名（如 `月度已支付销售额`）。使用显示名时，CLI 会在指定数据集内做精确匹配；如果显示名重名，命令会列出候选字段名，请改用字段名查询。`measure update` 和 `measure delete` 仍只接受字段名。

```bash
hbi measure show --app 4812 --dataset 3 "月度已支付销售额" --output json
```

创建或更新业务指标时，可以同时定义限定条件和时间轴；更新时还可以替换或清空分析维度：

* `-w, --where <HQL>`：限定条件 HQL；参数可重复，多个条件按 `AND` 组合。
* `-D, --dimension <FIELD_OR_LABEL>`：替换分析维度；可重复，也可以用逗号分隔。字段名优先于显示名，显示名按精确匹配解析。
* `--clear-dimensions`：清空全部分析维度，不能与 `--dimension` 同时使用。
* `--time-dimension <FIELD>`：时间轴字段名。
* `--time-granularity <GRANULARITY>`：时间粒度，可选值为 `year`、`qoy`、`quarter`、`moy`、`month`、`week`、`dom`、`dow`、`day`。

`--time-dimension` 和 `--time-granularity` 必须成对使用。`measure update` 显式传入限定条件或时间轴时，会使用这些参数定义的自定义分析语境，不再沿用已有的数据集粒度配置。

Sense 7.0 中，只有 AUTO 数据包的指标表达式和 `--where` 等 HQL 公式支持角色语义，例如 `{{2}}[buyer].{amount}`；其他场景中的角色没有意义。`measure --dimension` 和 `--time-dimension` 写入的是存储字段键：跨数据集时可显式使用 `{{dataset_id}}.{field}`，但不接受 `[role]` 后缀，也不会跨数据集自动解析裸字段。

```bash
hbi measure create --app 4812 --dataset 3 \
  --label "月度已支付销售额" \
  --expression "SUM({amount})" \
  --where "{status} = 'paid'" \
  --time-dimension order_date \
  --time-granularity month

hbi measure update --app 4812 --dataset 3 m1 \
  --dimension region \
  --dimension "商品类别,订单日期" \
  --where "{amount} > 0" \
  --time-dimension order_date \
  --time-granularity day

hbi measure update --app 4812 --dataset 3 m1 --clear-dimensions
```

**典型输出**：

```json
[
  {
    "id": 201,
    "name": "月度销售增长率",
    "expression": "PERCENTCHANGE(SUM({amount}), month({date}))",
    "datasetId": 3,
    "createdAt": "2025-03-15 11:00:00"
  }
]
```

**下一步常见动作**：

* 查看业务指标详情：`hbi measure show --app 4812 --dataset 3 m1 --output json`
* 搜索业务指标：`hbi measure query --app 4812 --query "销售" --output json`

## `pipeline`

**用途**：管理数据集成流程和节点。

**常见子命令**：

* 流程本体：`list` `show` `create` `update` `delete` `duplicate`
* 运行状态：`status` `errors` `schedule`
* 节点读写：`node` `edit`

**最小可用示例**：

```bash
hbi pipeline list --output json
```

**典型输出**：

```json
[
  {
    "id": 450,
    "title": "日报数据汇总",
    "createdAt": "2025-04-01 08:00:00",
    "updatedAt": "2026-05-25 10:00:00",
    "status": "success"
  }
]
```

**下一步常见动作**：

* 查看流程详情：`hbi pipeline show 450 --output json`
* 查看执行状态：`hbi pipeline status 450 --output json`
* 编辑节点：`hbi pipeline edit add 450 --help`

`edit` 是最常见的下一层入口，常见子命令包括：

* `add`
* `remove`
* `connect`

## `notebook`

**用途**：管理 Notebook、段落和执行相关配置。

**常见子命令**：

* Notebook 本体：`list` `show` `create` `update` `delete`
* 段落：`paragraphs` `add-paragraph` `update-paragraph` `execute` `delete-paragraph`
* 连接：`connections` `add-connection` `authorize-connection` `revoke-connection` `remove-connection`
* 其他：`schedule` `languages`

**最小可用示例**：

```bash
hbi notebook list --output json
```

**典型输出**：

```json
[
  {
    "id": 350,
    "title": "数据分析笔记",
    "createdAt": "2025-05-10 14:00:00",
    "updatedAt": "2026-06-01 09:30:00"
  }
]
```

**下一步常见动作**：

* 查看 Notebook 详情：`hbi notebook show 350 --output json`
* 列出段落：`hbi notebook paragraphs 350 --output json`
* 执行段落：`hbi notebook execute 350 para_123`

## `data-alert`

**用途**：管理数据预警。

**常见子命令**：

* `list` `show`
* `create` `update` `delete`
* `enable` `disable`
* `validate`

**最小可用示例**：

```bash
hbi data-alert list 4812 --output json
```

**典型输出**：

```json
[
  {
    "id": 520,
    "title": "日销售额预警",
    "enabled": true,
    "createdAt": "2025-06-01 10:00:00"
  }
]
```

**下一步常见动作**：

* 查看预警详情：`hbi data-alert show 4812 520 --output json`
* 启用预警：`hbi data-alert enable 4812 520`
* 禁用预警：`hbi data-alert disable 4812 520 --dry-run`

## `survey`

**用途**：管理数据填报模板（表单）与已提交的填报数据。

**常见子命令**：

* `list` `show`
* `create` `update` `delete`
* `setting get` `setting update`（只允许修改填报开关 `status`：`OPEN` / `CLOSED`）
* `data`（按模板查询已提交数据，支持 `--offset` / `--limit` / `--order-by` / `--order-type`）

**最小可用示例**：

```bash
hbi survey list --output json
hbi survey show 12 --output json
hbi survey setting get 12 --output json
hbi survey data 12 --limit 20 --order-by createdAt --order-type desc --output json
```

**多选控件（`checkboxInput`）**：

* `options.items` 必须是非空、无重复、无首尾空格的字符串数组；选项文案可以包含英文逗号。
* `options.styleType` 为 `checkbox` 或 `select`，`options.layout` 为 `vertical` 或 `horizontal`。
* 提交值是字符串数组，也接受 JSON 数组字符串；落库格式为 JSON 数组字符串，例如 `["研发","运维"]`。
* 批量导入以同一格式填写多选列；空选择存为 `NULL`。

**下一步常见动作**：

* 修改填报开关：`hbi survey setting update 12 --value '{"status":"CLOSED"}' --output json`
* 查看表单控件定义：`hbi survey show 12 --output json`

## `data-agent`

**用途**：管理 Data Agent / ChatBI 后台配置。

**常见子命令**：

* `config`
* `prompt`
* `vector`

**最小可用示例**：

```bash
hbi data-agent config get --output json
```

**典型输出**：

```json
{
  "enabled": true,
  "model": "gpt-4",
  "basePrompt": "你是一个数据分析助手",
  "updatedAt": "2026-05-30 16:00:00"
}
```

**下一步常见动作**：

* 查看 prompt 列表：`hbi data-agent prompt list --output json`
* 查看向量化状态：`hbi data-agent vector status --output json`

## 继续下钻建议

| 场景 | 先进入哪层命令树 |
| --- | --- |
| 数据连接、库表浏览、连通性测试 | `connection` |
| 数据集生命周期、预览、字段与粒度 | `dataset` |
| 联表关系与模型查询 | `data-model` |
| 数据集成流程本体 | `pipeline` |
| 节点增删改连线 | `pipeline edit` |
| Notebook、段落与连接 | `notebook` |
| 预警定义与启停 | `data-alert` |
| Data Agent 配置、Prompt 与向量状态 | `data-agent` |

需要具体参数和示例时，再在终端查看对应层级的 `--help`。
