惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 黄洪波

安装openclaw 排查项目中依赖的mybatis 拦截器 ModelAttribute 老革命遇上新问题 使用calcite构造ddl建表语句 OpenWebUI单点登录之解决动态参数问题 IDEA自带的Maven 3.9.x无法刷新http nexus私服(转) windows docker安装rocketmq之踩坑记 分布式系统设计经典论文(转载) 训练自己的yolo-v11数据集(二) 训练自己的yolo-v11数据集(一) 本地使用pycharm进行yolo推理 2024年的云原生架构需要哪些技术栈 (转) yolo v11学习,入门篇 - 黄洪波 OpenWebUI单点登录之深坑 AI工具验证 解决Win10无法进入睡眠模式(转) idea常用插件 内网离线模式下激活JRebel 将SpringBoot打包之后的jar设为守护进程
java导入json数据至doris
黄洪波 · 2024-09-09 · via 博客园 - 黄洪波

表结构字段名称与json  key名称一致:

package com.ruoyi.doris;


import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.nio.charset.Charset;
import java.util.UUID;


@Slf4j
public class PurReqLineTest {
public static void main(String[] args) throws Exception {
        // be
        String host = "192.168.0.132";
        // be接口
        int port = 8030;
        String database = "br";
        String table = "PurchaseRequestLines";
        String user = "root";
        String passwd = "xxx";
//        String s = "[{\"longitude\": \"19\", \"city\": \"北京\", \"latitude\": \"39.916927\"},{\"longitude\": \"2010\", \"city\": \"北京\", \"latitude\": \"39.916927\"}]";

        String s = FileUtil.readString(new File("D:\\采购需求.txt"), Charset.defaultCharset());
//        System.out.println(s);
        JSONArray value = JSONObject.parseObject(s).getJSONArray("value");
        log.info("size {}", value.size());


        for(int i=0;i<value.size(); i++){

                JSONArray linesArray  = value.getJSONObject(i).getJSONArray("DocumentLines");

                for(int j=0; j<linesArray.size(); j++) {
                        JSONObject lineObj = linesArray.getJSONObject(j);
                        log.info("{}",lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString());
                        lineObj.put("LineEntryId", lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString());
                        linesArray.set(j, lineObj);

                        String label = getUUID();
                        HttpResponse response = 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(lineObj.toString()).setFollowRedirects(true)
                                .execute();

                        log.info(response.body());

//                        Thread.sleep(3*1000);
                }

                
        }



        }


public static String getUUID() {
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
        }
        }

表结构字段名称与json key不一致

package com.ruoyi.doris;


import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.nio.charset.Charset;
import java.util.UUID;


@Slf4j
public class PurReqLineTest {
public static void main(String[] args) throws Exception {
        // be
        String host = "192.168.0.132";
        // be接口
        int port = 8030;
        String database = "br";
        String table = "PurchaseRequestLines";
        String user = "root";
        String passwd = "xxxx";
//        String s = "[{\"longitude\": \"19\", \"city\": \"北京\", \"latitude\": \"39.916927\"},{\"longitude\": \"2010\", \"city\": \"北京\", \"latitude\": \"39.916927\"}]";

        String s = FileUtil.readString(new File("D:\\采购需求.txt"), Charset.defaultCharset());
//        System.out.println(s);
        JSONArray value = JSONObject.parseObject(s).getJSONArray("value");
        log.info("size {}", value.size());


        for(int i=0;i<value.size(); i++){

                JSONArray linesArray  = value.getJSONObject(i).getJSONArray("DocumentLines");

                for(int j=0; j<linesArray.size(); j++) {
                        JSONObject lineObj = linesArray.getJSONObject(j);
                        log.info("{}",lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString());
                        lineObj.put("LineEntryId", lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString());
                        linesArray.set(j, lineObj);

                        String label = getUUID();
                        HttpResponse response = 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(lineObj.toString()).setFollowRedirects(true)
                                .execute();

                        log.info(response.body());

//                        Thread.sleep(3*1000);
                }


        }



        }


public static String getUUID() {
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
        }
        }