ObjectSet SQL 查询
更新时间:2026-09-24
接口描述
以 SQL 语句查询命名的 ObjectSet,支持多对象集 JOIN 查询。
权限说明
需具备对应工作空间及本体(ontology)的数据查看权限。
注意事项
- workspaceId、ontology 不存在或无权限时,请求会失败。
请求结构
Plain Text
1POST /v1/workspaces/{workspaceId}/ontologies/{ontology}/objectSets/executeQuery HTTP/1.1
2Host: databuilder.bd.baidubce.com
3Authorization: authorization string
4
5{
6 "objectSets": {
7 "emp": { "type": "base", "objectType": "Employee" },
8 "dept": { "type": "base", "objectType": "Department" }
9 },
10 "sql": "SELECT emp.name, dept.name FROM emp JOIN dept ON emp.dept_id = dept.id"
11}
请求头域
除公共头域(含 Authorization 鉴权)外,无其它特殊头域。
请求参数
Path 参数
| 参数名 | 类型 | 是否必须 | 含义 |
|---|---|---|---|
| workspaceId | String | 是 | 工作空间 ID |
| ontology | String | 是 | 本体名称 |
Body 参数(application/json)
执行自定义 SQL 查询请求体,支持多个 ObjectSet 与 SQL 结合查询。
| 参数名 | 类型 | 是否必须 | 含义 |
|---|---|---|---|
| objectSets | Map<String, Object> | 是 | 命名的 ObjectSet 映射,key 在 SQL 中可直接作为表名引用;value 为 ObjectSet 定义,见下 |
| sql | String | 是 | SQL 查询语句(标准 Spark SQL 语法),objectSets 中定义的 key 可直接作为表名使用。规则见下 |
sql 规则:
- SELECT 列名使用 apiName(系统自动映射到物理列名)
- 只支持 SELECT 查询;不支持 DML/DDL 和多语句
- LIMIT 最大 10000;不指定时默认返回 10000 条
- OFFSET 最大 1,000,000
objectSets 的 value(ObjectSet 定义)
ObjectSet 定义,支持递归嵌套结构。
| 参数名 | 类型 | 是否必须 | 含义 |
|---|---|---|---|
| type | String | 是 | ObjectSet 类型:base、filter、searchAround、intersect、union、subtract、parameter。注意:parameter 类型仅 ActionType 内部使用,直接调用不应使用此类型 |
| objectType | String | 否 | 当 type = base 时指定 objectType 名称;当 type = searchAround 时指定目标 objectType 名称 |
| parameterId | String | 否 | 当 type = parameter 时指定参数 ID(仅供 ActionType 内部使用) |
| objectSet | Object | 否 | 当 type = filter 或 searchAround 时,指定嵌套的 objectSet |
| where | Object | 否 | 当 type = filter 时,指定过滤条件,见下 |
| link | String | 否 | 当 type = searchAround 时,指定关联的 link 名称(需同时指定 objectType) |
| objectSets | Array<Object> | 否 | 当 type = intersect、union、subtract 时,指定多个 objectSet |
where 定义
| 参数名 | 类型 | 是否必须 | 含义 |
|---|---|---|---|
| type | String | 否 | 条件类型,支持的运算符见下表 |
| field | String | 否 | 叶子条件使用,属性名 |
| value | - | 否 | 叶子条件使用,属性值;类型根据条件类型而定 |
| filter | Array<Object> | 否 | 组合条件(and/or/not)使用,元素结构同 where |
where.type 支持的运算符:
| 类别 | 运算符 |
|---|---|
| 比较类 | eq(等于)、ne(不等于)、lt(小于)、le/lte(小于等于)、gt(大于)、ge/gte(大于等于) |
| 集合类 | in(包含于)、not_in(不包含于) |
| 字符串类 | like(模糊匹配)、not_like(不匹配)、starts_with(前缀匹配)、ends_with(后缀匹配) |
| 空值类 | is_null(为空)、is_not_null(非空) |
| 向量类 | contains(向量搜索)、match_any、match_all、match_phrase、match_phrase_prefix、match_regexp |
| 逻辑类 | and、or、not |
响应头域
除公共头域外,无其它特殊头域。
响应参数
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| requestId | String | 是 | 请求 ID |
| code | String | 是 | 业务响应状态码 |
| message | String | 否 | 失败时返回错误信息 |
| result | Object | 是 | 响应结果主体,见下 |
result
| 参数名 | 类型 | 是否必须 | 说明 |
|---|---|---|---|
| data | Array<Object> | 否 | 返回的数据列表,key 为列名 |
| sql | String | 否 | 本次执行的 SQL 语句(调试用,仅特定配置下返回),用户侧不要使用 |
错误码
通用错误码可参考如下(本体接口专属错误码待确认,以最新实现为准):
| 错误码 | 错误描述 | HTTP 状态码 | 中文解释 |
|---|---|---|---|
| AccessDenied | 无操作权限 | 403 | 暂无操作权限 |
| IllegalArgument | 参数非法 | 400 | 用户提供参数错误 |
请求示例
Plain Text
1{
2 "objectSets": {
3 "property1": {
4 "type": "base",
5 "objectType": "string",
6 "parameterId": "string",
7 "objectSet": {},
8 "where": {
9 "type": "string",
10 "field": "string",
11 "value": {},
12 "filter": [
13 {}
14 ]
15 },
16 "link": "string",
17 "objectSets": [
18 {}
19 ]
20 },
21 "property2": {
22 "type": "base",
23 "objectType": "string",
24 "parameterId": "string",
25 "objectSet": {},
26 "where": {
27 "type": "string",
28 "field": "string",
29 "value": {},
30 "filter": [
31 {}
32 ]
33 },
34 "link": "string",
35 "objectSets": [
36 {}
37 ]
38 }
39 }
40}
响应示例
JSON
1{
2 "requestId": "string",
3 "code": "string",
4 "message": "string",
5 "result": {
6 "data": [
7 {}
8 ]
9 }
10}
评价此篇文章
