栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Doris-0.15-导入Json数据

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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依赖
    
      cn.hutool
      hutool-http
      5.7.22
    
    
  • LoadJson.java

    import cn.hutool.http.HttpRequest;
    import cn.hutool.http.HttpResponse;
    import java.util.UUID;
    
    
    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;
        }
    }
    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/821621.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号