Skip to content

段落

段落说明

段落定义

段落是一个笔记中的一个代码片段,由多个语句构成,来共同完成特定的数据处理功能。段落中的代码支持SQL和HQL,但是同一个段落中代码只能是同一种的,不能混合包含不同类型的代码。

段落结构说明

字段类型描述
idINTEGER段落的 id
previousIdINTEGER段落的前一个段落的 id
notebookIdINTEGER段落所属的笔记的 id
createdAtDATETIME段落创建的时间
createdByINTEGER段落创建用户的 id
updatedAtDATETIME段落最后修改的时间
updatedByINTEGER段落最后修改用户的 id
codeSTRING段落的代码,每个语句用英文分号分隔
langSTRING段落的代码类型,见段落语言说明,默认是SQL
connectionIdINTEGER段落的执行目标连接的 id
hsVersionINTEGER段落的编辑版本号,从0开始,修改段落提交的时候,需要带上修改前的版本号
optionsOBJECT段落配置信息
options.pathSTRING 数组段落的执行目标连接的路径(schema),有些数据源比如SQL Server有多层

段落语言说明

状态值意义
SQLnative SQl,默认值,语法和具体的连接类型相关
HQLHQL,衡石定义的通用语言

接口说明

新增段落

请求URL

http
POST /api/notebooks/{notebookId}/paragraphs HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
Request Body 参数
字段类型是否必须描述
previousIdINTEGER分情况段落的前一个段落的 id。笔记的第一个段落的前一个段落id是null,可不填;后续的段落必须填
codeSTRING可选段落的代码,每个语句用英文分号分隔,默认为空
langSTRING可选段落的代码类型,见段落语言说明,默认是SQL
connectionIdINTEGER可选段落的执行目标连接的 id,默认为null,可以后续再修改
optionsOBJECT可选段落配置信息
options.pathSTRING 数组可选段落的执行目标连接的路径(schema),有些数据源比如SQL Server有多层

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
dataOBJECT段落结构说明

接口示例: 创建笔记的第一个段落

http
POST /api/notebooks/{notebookId}/paragraphs HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "id": 1,
        "notebookId": 1,
        "createdBy": 1,
        "createdAt": "2020-02-25 17:19:40",
        "updatedBy": 1,
        "updatedAt": "2020-02-25 17:19:40",
        "code": "",
        "lang": "SQL",
        "hsVersion": 0,
        "options": {},
        "isDelete": false
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

接口示例: 创建笔记的第二个段落

http
POST /api/notebooks/{notebookId}/paragraphs HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
    "previousId": 1
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "id": 2,
        "previousId": 1,
        "notebookId": 1,
        "createdBy": 1,
        "createdAt": "2020-02-26 17:19:40",
        "updatedBy": 1,
        "updatedAt": "2020-02-26 17:19:40",
        "code": "",
        "lang": "SQL",
        "hsVersion": 0,
        "options": {},
        "isDelete": false
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

删除段落

请求URL

http
DELETE /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
Request Body 参数
字段类型是否必须描述

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
code错误码请求成功返回0
msgSTRING请求成功返回success

接口示例:

http
DELETE /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

修改段落

请求URL

http
PUT /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
Request Body 参数

只能修改connectionId,options.path,code,lang这4个参数中的一个或者多个。不能全部为(空或者null)

字段类型是否必须描述
codeSTRING可选段落的代码,每个语句用英文分号分隔,默认为空
langSTRING可选段落的代码类型,见段落语言说明,默认是SQL
connectionIdINTEGER可选段落的执行目标连接的 id,默认为null,可以后续再修改
optionsOBJECT可选段落配置信息
options.pathSTRING 数组可选段落的执行目标连接的路径(schema),有些数据源比如SQL Server有多层
hsVersionINTEGER可选段落的编辑版本号,从0开始,修改段落提交的时候,需要带上修改前的版本号。不带版本号不检查版本冲突

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
dataOBJECT段落结构说明

接口示例: 修改代码

http
PUT /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
    "code": "select * from movie limit 10"
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "id": 1,
        "notebookId": 1,
        "createdBy": 1,
        "createdAt": "2020-02-25 17:19:40",
        "updatedBy": 1,
        "updatedAt": "2020-02-27 17:19:40",
        "code": "select * from movie limit 10",
        "lang": "SQL",
        "hsVersion": 1,
        "options": {},
        "isDelete": false
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

接口示例: 修改默认执行schema和执行连接

http
PUT /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
    "connectionId": 1,
    "options": {
        "path": ["sqlserverdb","schema"]
    }
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "id": 1,
        "notebookId": 1,
        "createdBy": 1,
        "createdAt": "2020-02-25 17:19:40",
        "updatedBy": 1,
        "updatedAt": "2020-02-27 18:19:40",
        "code": "select * from movie limit 10",
        "lang": "SQL",
        "hsVersion": 2,
        "connectionId": 1,
        "options": {
            "path": ["sqlserverdb","schema"]
        },
        "isDelete": false
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

获取段落

请求URL

http
GET /api/notebooks/{notebookId}/paragraphs/{paragraphId} HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
Request Body 参数
字段类型是否必须描述

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
dataOBJECT段落结构说明

接口示例:

http
GET /api/notebooks/{notebookId}/paragraphs/{paragrapId} HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "id": 1,
        "notebookId": 1,
        "createdBy": 1,
        "createdAt": "2020-02-25 17:19:40",
        "updatedBy": 1,
        "updatedAt": "2020-02-27 18:19:40",
        "code": "select * from movie limit 10",
        "lang": "SQL",
        "hsVersion": 2,
        "connectionId": 1,
        "options": {
            "path": ["sqlserverdb","schema"]
        },
        "isDelete": false
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

获取笔记的段落列表

请求URL

http
GET /api/notebooks/{notebookId}/paragraphs HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
offsetINTEGER可选分页偏移量,默认是0
limitINTEGER可选分页获取个数,默认是1000
Request Body 参数
字段类型是否必须描述

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
totalHitsINTEGER段落的总个数
offsetINTEGER当前分页偏移量
dataOBJECT 数组数组的元素是一个段落,见段落结构说明

接口示例:

http
GET /api/notebooks/{notebookId}/paragraphs HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": [
        {
            "id": 1,
            "notebookId": 1,
            "createdBy": 1,
            "createdAt": "2020-02-25 17:19:40",
            "updatedBy": 1,
            "updatedAt": "2020-02-27 18:19:40",
            "code": "select * from movie limit 10",
            "lang": "SQL",
            "hsVersion": 2,
            "connectionId": 1,
            "options": {
                "path": ["sqlserverdb","schema"]
            },
            "isDelete": false
        },
        {
            "id": 2,
            "previousId": 1,
            "notebookId": 1,
            "createdBy": 1,
            "createdAt": "2020-02-26 17:19:40",
            "updatedBy": 1,
            "updatedAt": "2020-02-28 18:19:40",
            "code": "select * from movie limit 10",
            "lang": "SQL",
            "hsVersion": 2,
            "connectionId": 1,
            "options": {
                "path": ["sqlserverdb","schema"]
            },
            "isDelete": false
        }
    ],
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
    "totalHits": 2,
    "offset": 0
}

执行一个段落

请求URL

http
POST /api/notebooks/{notebookId}/paragraphs/{paragrapId}/executions HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
requestIdSTRING请求唯一的id
isTestBOOL是否是测试执行
Request Body 参数
字段类型是否必须描述

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
dataOBJECT包含日志和执行结果
data.logsSTRING 数组每条都是执行日志
data.schemaOBJECT 数组每一个元素表示一个字段的属性,与数据集的字段结构相同
data.dataOBJECT 数组每一个元素是表示一行数据的数组

接口示例:

http
POST /api/notebooks/{notebookId}/paragraphs/{paragrapId}/executions?requestId=xxx123&isTest=true HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "data": {
        "logs": [
            "2020-03-03 17:10:08.13 [77] [pipelineId: 1 jobId: 1 nodeId: 2 taskId: 1] task start",
            "2020-03-03 17:10:08.409 [77] [pipelineId: 1 jobId: 1 nodeId: 2 taskId: 1] task done"
        ],
        "schema": [...],
        "data": [...]
    },
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

取消执行一个段落

请求URL

http
PUT /api/notebooks/{notebookId}/paragraphs/{paragrapId}/executions/cancel HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

URL 参数
字段类型是否必须说明
requestIdSTRING执行时发送的请求id
Request Body 参数
字段类型是否必须描述

返回对象的格式说明

字段类型说明
versionSTRING当前系统版本哈希值
code错误码请求成功返回0
msgSTRING请求成功返回success

接口示例:

http
PUT /api/notebooks/{notebookId}/paragraphs/{paragrapId}/executions/cancel?requestId=xxx123 HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request Body:
{
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
    "code": 0,
    "msg": "success",
    "version": "version@9a5e106#6730f0d",
}

HENGSHI SENSE API 使用手册