赞
踩
Stream Load是一种通过HTTP协议进行PUT操作,将数据导入到Doris。数据导入是同步操作,导入完成会返回成功或失败的response。一些具体的使用说明可以通过help stream load
获取
import requests from requests.auth import HTTPBasicAuth import uuid import json if __name__ == '__main__': url = 'http://192.168.8.112:7030/api/dataQualitySystem/test/_stream_load' json_data = {"records": [{"id": 3, "name": "zhangsan"}, {"id": 4, "name": "lisi"}]} doris_headers = { 'label': str(uuid.uuid1()), 'format': 'json', 'expect': '100 continue', 'strip_outer_array': "true", 'json_root': '$.records', 'where': 'id=3' } auth = HTTPBasicAuth('root', 'Root_123') response = requests.put(url=url, json=json_data, headers = doris_headers, auth = auth ) redict_url = response.url redict_headers = { 'label': str(uuid.uuid1()), 'format': 'json', 'strip_outer_array': "true", 'json_root': '$.records', 'where': 'id=3' } redict_response = requests.put(url=redict_url, json=json_data, headers = redict_headers, auth = auth ) if json.loads(redict_response.text).get("Status") != "Success": ex = Exception(redict_response.text) raise ex print(redict_response.text)
程序说明如下:
执行结果如下:
{ "TxnId": 201601, "Label": "c217d2f4-3dc5-11ec-862d-5cbaef5fa158", "Status": "Success", "Message": "OK", "NumberTotalRows": 2, "NumberLoadedRows": 1, "NumberFilteredRows": 0, "NumberUnselectedRows": 1, "LoadBytes": 71, "LoadTimeMs": 28, "BeginTxnTimeMs": 0, "StreamLoadPutTimeMs": 4, "ReadDataTimeMs": 0, "WriteDataTimeMs": 10, "CommitAndPublishTimeMs": 13 }
返回结果说明:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。