Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有嵌入式配置单元的java thrift客户端?_Java_Hive_Thrift - Fatal编程技术网

带有嵌入式配置单元的java thrift客户端?

带有嵌入式配置单元的java thrift客户端?,java,hive,thrift,Java,Hive,Thrift,根据这里的链接。上面说 Thrift Java客户端 在嵌入式模式和独立模式下运行 服务器 如何在嵌入式模式下使用配置单元运行thrift java客户端?因此,下面介绍如何在嵌入式模式下运行配置单元“thrift”客户端 import org.apache.hadoop.hive.service.HiveInterface; import org.apache.hadoop.hive.service.HiveServer; ... HiveInterface hiveClient = new

根据这里的链接。上面说

Thrift Java客户端 在嵌入式模式和独立模式下运行 服务器


如何在嵌入式模式下使用配置单元运行thrift java客户端?

因此,下面介绍如何在嵌入式模式下运行配置单元“thrift”客户端

import org.apache.hadoop.hive.service.HiveInterface;
import org.apache.hadoop.hive.service.HiveServer;
...
HiveInterface hiveClient = new HiveServer.HiveServerHandler();
将以下内容添加到类路径

$HIVE\u HOME/lib/*.jar

$HIVE\u HOME/conf


我在这里的配置单元源代码$hive_HOME/src/jdbc/src/java/./HiveConnection.java

配置单元使用Thrift作为RPC框架,Thrift RPC使“在嵌入式模式和独立服务器上都可以操作”变得很容易

客户端模式(连接到独立服务器) 嵌入式模式(无外部服务器) 这个问题真的很老了,但我仍然需要一些解决方案,但是google/so/HiveWiki上没有任何有用的信息,所以我深入研究了源代码并找到了这些

全部基于Hive 3.1.2

参考:

  • org.apache.hive.service.server.HiveServer2
  • org.apache.hive.service.cli.CLIServiceTest
  • org.apache.hive.service.cli.thrift.ThriftCLIServiceTest
    HiveConf hiveConf = new HiveConf();
    hiveConf.addResource("/Users/tzp/pppathh/hive-site.xml");

    TTransport transport = new TSocket("127.0.0.1", 10000);
    transport = PlainSaslHelper.getPlainTransport(USERNAME, PASSWORD, transport);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    transport.open();

    ThriftCLIServiceClient cliServiceClient = new ThriftCLIServiceClient(new TCLIService.Client(protocol), hiveConf);
    SessionHandle sessionHandle = cliServiceClient.openSession(USERNAME, PASSWORD);

    OperationHandle operationHandle = cliServiceClient.executeStatement(sessionHandle, "select * from u_data_ex limit 2", null);
    RowSet results = cliServiceClient.fetchResults(operationHandle);

    for (Object[] result : results) {
        System.out.println(Arrays.asList(result));
    }
    HiveConf hiveConf = new HiveConf();
    hiveConf.addResource("/Users/tzp/ppppathh/hive-site.xml");
    hiveConf.set("fs.defaultFS", "hdfs://localhost:9000");

    EmbeddedThriftBinaryCLIService service = new EmbeddedThriftBinaryCLIService();
    service.init(hiveConf);

    ICLIService icliService = service.getService();
    SessionHandle sessionHandle = icliService.openSession(USERNAME, PASSWORD, null);

    OperationHandle operationHandle = icliService.executeStatement(sessionHandle, "select * from u_data_ex limit 2", null);
    RowSet results = icliService.fetchResults(operationHandle);

    for (Object[] result : results) {
        System.out.println(Arrays.asList(result));
    }