2024年最全Doris:读取Doris数据的N种方法_访问 doris,阿里大牛教你自己写大数据开发第三方库

2024年最全Doris:读取Doris数据的N种方法_访问 doris,阿里大牛教你自己写大数据开发第三方库_第1张图片
2024年最全Doris:读取Doris数据的N种方法_访问 doris,阿里大牛教你自己写大数据开发第三方库_第2张图片

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

        arrow-memory-netty
        ${arrow.version}
        runtime
    

```

编码实现:

package com.yichenkeji.doris;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.*;
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.ipc.ArrowStreamReader;
import org.apache.arrow.vector.types.Types;
import org.apache.commons.codec.binary.Base64;
import org.apache.doris.sdk.thrift.*;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.thrift.TConfiguration;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class QueryPlanMain {
    private static String queryPlanUrlFormat = "%s/api/%s/%s/_query_plan";


    public static void main(String[] args) throws Exception {
        String dorisUrl = "http://127.0.0.1:8030";
        String username = "root";
        String password = "1234564";
        String database = "article";
        String table = "dim_user";
//        String[] columns = {"id","name","merger_name","area_code","level"};
        String[] columns = {"*"};
        String sql ="select "+String.join(",",columns)+" from "+database+"."+table
//                +" where id<= 10 "
//                + " order by id " //不支持order by
//                + " limit 10" //不支持limit
                ;
        JSONObject queryPlanResult = getQueryPlan(dorisUrl,username,password,database,table,sql);
        System.out.println("查询计划执行结果:"+queryPlanResult);
        //根据查询计划结果,查询数据
        if (queryPlanResult != null){
            readData(queryPlanResult,username,password,database,table);
        }
    }

    private static JSONObject getQueryPlan(String dorisUrl, String username,String password,String database, String table, String sql) throws Exception {
        try (CloseableHttpClient client = HttpClients.custom().build()) {

            String queryPlanUrl = String.format(queryPlanUrlFormat, dorisUrl, database, table);


            HttpPost post = new HttpPost(queryPlanUrl);
            System.out.println("执行查询计划url: "+queryPlanUrl);
            post.setHeader(HttpHeaders.EXPECT, "100-continue");
            post.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader(username, password));

            // The param is specific SQL, and the query

你可能感兴趣的:(程序员,大数据)