Doris-0.15-导入Json数据

Stream load之json数据导入

Stream load 是一个同步的导入方式,用户通过发送 HTTP 协议发送请求将本地文件或数据流导入到 Doris 中。Stream load 同步执行导入并返回导入结果。用户可直接通过请求的返回体判断本次导入是否成功。

Stream load 主要适用于导入本地文件,或通过程序导入数据流中的数据。

取消导入

用户无法手动取消 Stream load,Stream load 在超时或者导入错误后会被系统自动取消。

相关系统配置

FE 配置
  • stream_load_default_timeout_second

    导入任务的超时时间(以秒为单位),导入任务在设定的 timeout 时间内未完成则会被系统取消,变成 CANCELLED。

    默认的 timeout 时间为 600 秒。如果导入的源文件无法在规定时间内完成导入,用户可以在 stream load 请求中设置单独的超时时间。

    或者调整 FE 的参数stream_load_default_timeout_second 来设置全局的默认超时时间。

BE 配置
  • streaming_load_max_mb

    Stream load 的最大导入大小,默认为 10G,单位是 MB。如果用户的原始文件超过这个值,则需要调整 BE 的参数 streaming_load_max_mb

具体请参考官方文档,这里直接上代码了.

官方文档链接: https://doris.apache.org/zh-CN/administrator-guide/load-data/stream-load-manual.html#%E5%88%9B%E5%BB%BA%E5%AF%BC%E5%85%A5

  • 加入pom依赖
    <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-http</artifactId>
      <version>5.7.22</version>
    </dependency>
    
  • LoadJson.java

    import cn.hutool.http.HttpRequest;
    import cn.hutool.http.HttpResponse;
    import java.util.UUID;
    
    /**
     * @Author: M.J
     * @Date: 2022/4/19 0019 14:27
     */
    public class LoadJson.java {
        public static void main(String[] args) throws Exception {
    				// be
            String host = "192.168.31.62";
          	// be接口
            int port = 8030;
            String database = "xxx";
            String table = "xxx";
            String user = "root";
            String passwd = "";
            String label = getUUID();
            String s = "[{\"longitude\": \"19\", \"city\": \"北京\", \"latitude\": \"39.916927\"},{\"longitude\": \"20\", \"city\": \"北京\", \"latitude\": \"39.916927\"}]";
    
            HttpResponse execute = HttpRequest.put("http://" + host + ":" + port + "/api/" + database + "/" + table + "/_stream_load")
                    .basicAuth(user, passwd)
                    .header("Expect", "100-continue")
                    .header("label", label)
                    .header("Content-Type", "text/plain; charset=UTF-8")
                    .header("format", "json")
              			// 导入json数组
                    .header("strip_outer_array", "true")
                    .body(s).setFollowRedirects(true)
                    .execute();
            System.out.println(execute);
    
        }
    
    
        public static String getUUID() {
            String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
            return uuid;
        }
    }
    
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值