0


spring boot 引入hive

在Spring Boot中使用Hive,需要引入以下依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-hadoop</artifactId>
</dependency>

然后,在

application.properties

中配置Hive相关信息:

spring.hadoop.config.fs.defaultFS=hdfs://namenode:8020
spring.hadoop.config.hive.metastore.uri=thrift://metastore:9083

其中,

fs.defaultFS

指定HDFS的地址,

hive.metastore.uri

指定Hive的元数据服务地址。

使用Hive可以通过以下方式:

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.Driver;
import org.apache.hadoop.hive.ql.parse.ParseException;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.SQLException;

@Service
public class HiveService {
    @Autowired
    private HiveConf hiveConf;

    public void useHive() throws IOException, SQLException, ParseException, SemanticException {
        Driver driver = new Driver(hiveConf);
        driver.run("SHOW DATABASES");
    }
}

其中,

HiveConf

可以从Spring容器中自动注入。在这个例子中,使用Hive的

Driver

执行了一条

SHOW DATABASES

的SQL查询语句。

标签: spring boot hive 后端

本文转载自: https://blog.csdn.net/qq_36204764/article/details/131652661
版权归原作者 、小H 所有, 如有侵权,请联系我们删除。

“spring boot 引入hive”的评论:

还没有评论