Springboot with Impala and Kudu

转自

How to run this app

Please follow the instructions below to get kudu running locally with java and impala driver.

Download the kudu quickstart VM

Kudu Quick Start VM

Create the department file to load

You can use this python script to create the department file to load: name it generate.py

#!/usr/local/bin/python3
default_path = '/Users/ryang1/Desktop'
def generateDepartmentMasterFile():
    """
    Company Id | Department Code | Department Description
    """
    file = open(default_path+'/dept.txt','a')
    for x in range (1,501):
        file.write('Company{0}|{0}|Dept{0} 
Description\n'.format(str(x)))
generateDepartmentMasterFile()

Run it using

$ python3 generate.py

Load the department file

Start your kudu quickstart VM. Once it has started run this command to find the vm ip. Should start with 192.168.*

$ ip addr show
[demo@quickstart ~]$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 08:00:27:8a:40:9a brd ff:ff:ff:ff:ff:ff
    inet 192.168.57.100/24 brd 192.168.57.255 scope global 
eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 08:00:27:16:94:b5 brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.15/24 brd 10.0.3.255 scope global eth1

Once you figure out your vm ip address, we will copy over the dept.txt file we created earlier with the python script and put it into hdfs.

ssh username:demo password:demo

$ scp dept.txt demo@192.168.57.100:~/
$ ssh demo@192.168.57.100
$ hdfs dfs -put -f dept.txt /data/dept

Create the department table in kudu/impala

CREATE EXTERNAL TABLE department_raw (
    company_id string,
    department_code int,
    department_description string)
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY '|'
    LOCATION '/data/dept/';
CREATE TABLE department
DISTRIBUTE BY HASH (company_id) INTO 16 BUCKETS
TBLPROPERTIES(
'storage_handler' = 
'com.cloudera.kudu.hive.KuduStorageHandler',
'kudu.table_name' = 'department',
'kudu.master_addresses' = '127.0.0.1',
'kudu.key_columns' = 'company_id'
 ) AS SELECT * FROM department_raw;
# Set the database configuration

In the project search for src/main/java/config/DatabaseConfig.java and set the datasource url to your kudu/impala VM url

@Bean(name="dataSource")
public DataSource dataSource() {
    DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();

    //CHANGE ME!
    dataSourceBuilder.url("jdbc:impala://192.168.57.100:21050");

    dataSourceBuilder.username("demo");
    dataSourceBuilder.password("demo");
    dataSourceBuilder.driverClassName("com.cloudera.impala.jdbc4.Driver");
    return dataSourceBuilder.build();
}

Setting up intellij

In order to run the spring boot app you will need to set the run configuration Run -> Edit Configurations Press the + icon create a new maven entry name it to springboot-run change the command line input field to

spring-boot:run

hit apply/save.

You are all set. Hit run.

To see it in action go to your browser and visit url: http://localhost:8080/department?companyId=Company1

`spring boot demo` 是一个用来深度学习并实战 `spring boot` 的项目,目前总共包含 **`63`** 个集成demo,已经完成 **`51`** 个。 该项目已成功集成 actuator(`监控`)、admin(`可视化监控`)、logback(`日志`)、aopLog(`通过AOP记录web请求日志`)、统一异常处理(`json级别和页面级别`)、freemarker(`模板引擎`)、thymeleaf(`模板引擎`)、Beetl(`模板引擎`)、Enjoy(`模板引擎`)、JdbcTemplate(`通用JDBC操作数据库`)、JPA(`强大的ORM框架`)、mybatis(`强大的ORM框架`)、通用Mapper(`快速操作Mybatis`)、PageHelper(`通用的Mybatis分页插件`)、mybatis-plus(`快速操作Mybatis`)、BeetlSQL(`强大的ORM框架`)、upload(`本地文件上传和七牛云文件上传`)、redis(`缓存`)、ehcache(`缓存`)、email(`发送各种类型邮件`)、task(`基础定时任务`)、quartz(`动态管理定时任务`)、xxl-job(`分布式定时任务`)、swagger(`API接口管理测试`)、security(`基于RBAC的动态权限认证`)、SpringSession(`Session共享`)、Zookeeper(`结合AOP实现分布式锁`)、RabbitMQ(`消息队列`)、Kafka(`消息队列`)、websocket(`服务端推送监控服务器运行信息`)、socket.io(`聊天室`)、ureport2(`中国式报表`)、打包成`war`文件、集成 ElasticSearch(`基本操作和高级查询`)、Async(`异步任务`)、集成Dubbo(`采用官方的starter`)、MongoDB(`文档数据库`)、neo4j(`图数据库`)、docker(`容器化`)、`JPA多数据源`、`Mybatis多数据源`、`代码生成器`、GrayLog(`日志收集`)、JustAuth(`第三方登录`)、LDAP(`增删改查`)、`动态添加/切换数据源`、单机限流(`AOP + Guava RateLimiter`)、ElasticSearch 7.x(`使用官方 Rest High Level Client`)。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值