最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot2 整合 ClickHouse數(shù)據(jù)庫案例解析

 更新時(shí)間:2019年10月23日 08:54:04   作者:知了一笑  
這篇文章主要介紹了SpringBoot2 整合 ClickHouse數(shù)據(jù)庫案例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

一、ClickHouse簡介

1、基礎(chǔ)簡介

Yandex開源的數(shù)據(jù)分析的數(shù)據(jù)庫,名字叫做ClickHouse,適合流式或批次入庫的時(shí)序數(shù)據(jù)。ClickHouse不應(yīng)該被用作通用數(shù)據(jù)庫,而是作為超高性能的海量數(shù)據(jù)快速查詢的分布式實(shí)時(shí)處理平臺(tái),在數(shù)據(jù)匯總查詢方面(如GROUP BY),ClickHouse的查詢速度非常快。

2、數(shù)據(jù)分析能力

OLAP場(chǎng)景特征

  • · 大多數(shù)是讀請(qǐng)求
  • · 數(shù)據(jù)總是以相當(dāng)大的批(> 1000 rows)進(jìn)行寫入
  • · 不修改已添加的數(shù)據(jù)
  • · 每次查詢都從數(shù)據(jù)庫中讀取大量的行,但是同時(shí)又僅需要少量的列
  • · 寬表,即每個(gè)表包含著大量的列
  • · 較少的查詢(通常每臺(tái)服務(wù)器每秒數(shù)百個(gè)查詢或更少)
  • · 對(duì)于簡單查詢,允許延遲大約50毫秒
  • · 列中的數(shù)據(jù)相對(duì)較小: 數(shù)字和短字符串(例如,每個(gè)URL 60個(gè)字節(jié))
  • · 處理單個(gè)查詢時(shí)需要高吞吐量(每個(gè)服務(wù)器每秒高達(dá)數(shù)十億行)
  • · 事務(wù)不是必須的
  • · 對(duì)數(shù)據(jù)一致性要求低
  • · 每一個(gè)查詢除了一個(gè)大表外都很小
  • · 查詢結(jié)果明顯小于源數(shù)據(jù),換句話說,數(shù)據(jù)被過濾或聚合后能夠被盛放在單臺(tái)服務(wù)器的內(nèi)存中

列式數(shù)據(jù)存儲(chǔ)

(1)、行式數(shù)據(jù)

(2)、列式數(shù)據(jù)

(3)、對(duì)比分析

分析類查詢,通常只需要讀取表的一小部分列。在列式數(shù)據(jù)庫中可以只讀取需要的數(shù)據(jù)。數(shù)據(jù)總是打包成批量讀取的,所以壓縮是非常容易的。同時(shí)數(shù)據(jù)按列分別存儲(chǔ)這也更容易壓縮。這進(jìn)一步降低了I/O的體積。由于I/O的降低,這將幫助更多的數(shù)據(jù)被系統(tǒng)緩存。

二、整合SpringBoot框架

該案例基于:Druid連接池和mybatis進(jìn)行整合。Druid 1.1.10 版本 SQL Parser對(duì)clickhouse的開始提供支持。

1、核心依賴

<dependency>
  <groupId>ru.yandex.clickhouse</groupId>
  <artifactId>clickhouse-jdbc</artifactId>
  <version>0.1.53</version>
</dependency>

2、配屬數(shù)據(jù)源

spring:
 datasource:
  type: com.alibaba.druid.pool.DruidDataSource
  click:
   driverClassName: ru.yandex.clickhouse.ClickHouseDriver
   url: jdbc:clickhouse://127.0.0.1:8123/default
   initialSize: 10
   maxActive: 100
   minIdle: 10
   maxWait: 6000

3、Druid連接池配置

@Configuration
public class DruidConfig {
  @Resource
  private JdbcParamConfig jdbcParamConfig ;
  @Bean
  public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(jdbcParamConfig.getUrl());
    datasource.setDriverClassName(jdbcParamConfig.getDriverClassName());
    datasource.setInitialSize(jdbcParamConfig.getInitialSize());
    datasource.setMinIdle(jdbcParamConfig.getMinIdle());
    datasource.setMaxActive(jdbcParamConfig.getMaxActive());
    datasource.setMaxWait(jdbcParamConfig.getMaxWait());
    return datasource;
  }
}

4、參數(shù)配置類

@Component
@ConfigurationProperties(prefix = "spring.datasource.click")
public class JdbcParamConfig {
  private String driverClassName ;
  private String url ;
  private Integer initialSize ;
  private Integer maxActive ;
  private Integer minIdle ;
  private Integer maxWait ;
  // 省略 GET 和 SET
}

這樣整合代碼就完成了。

三、操作案例演示

1、Mapper接口

public interface UserInfoMapper {
  // 寫入數(shù)據(jù)
  void saveData (UserInfo userInfo) ;
  // ID 查詢
  UserInfo selectById (@Param("id") Integer id) ;
  // 查詢?nèi)?
  List<UserInfo> selectList () ;
}

這里就演示簡單的三個(gè)接口。

2、Mapper.xml文件

<mapper namespace="com.click.house.mapper.UserInfoMapper">
  <resultMap id="BaseResultMap" type="com.click.house.entity.UserInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="user_name" jdbcType="VARCHAR" property="userName" />
    <result column="pass_word" jdbcType="VARCHAR" property="passWord" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="create_day" jdbcType="VARCHAR" property="createDay" />
  </resultMap>
  <sql id="Base_Column_List">
    id,user_name,pass_word,phone,email,create_day
  </sql>
  <insert id="saveData" parameterType="com.click.house.entity.UserInfo" >
    INSERT INTO cs_user_info
    (id,user_name,pass_word,phone,email,create_day)
    VALUES
    (#{id,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},#{passWord,jdbcType=VARCHAR},
    #{phone,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},#{createDay,jdbcType=VARCHAR})
  </insert>
  <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from cs_user_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectList" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from cs_user_info
  </select>
</mapper>

這里 create_day 是以字符串的方式在轉(zhuǎn)換,這里需要注意下。

3、控制層接口

@RestController
@RequestMapping("/user")
public class UserInfoController {
  @Resource
  private UserInfoService userInfoService ;
  @RequestMapping("/saveData")
  public String saveData (){
    UserInfo userInfo = new UserInfo () ;
    userInfo.setId(4);
    userInfo.setUserName("winter");
    userInfo.setPassWord("567");
    userInfo.setPhone("13977776789");
    userInfo.setEmail("winter");
    userInfo.setCreateDay("2020-02-20");
    userInfoService.saveData(userInfo);
    return "sus";
  }
  @RequestMapping("/selectById")
  public UserInfo selectById () {
    return userInfoService.selectById(1) ;
  }
  @RequestMapping("/selectList")
  public List<UserInfo> selectList () {
    return userInfoService.selectList() ;
  }
}

四、源代碼地址

GitHub·地址

https://github.com/cicadasmile/middle-ware-parent

GitEE·地址

https://gitee.com/cicadasmile/middle-ware-parent

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

盐津县| 昭通市| 潼南县| 新巴尔虎左旗| 汝阳县| 正宁县| 桐乡市| 水城县| 垫江县| 信丰县| 江达县| 神木县| 洛扎县| 海兴县| 长寿区| 绵阳市| 隆尧县| 芜湖市| 涟源市| 饶平县| 临安市| 乌拉特后旗| 双峰县| 来凤县| 岳西县| 双牌县| 新竹市| 清镇市| 玛曲县| 册亨县| 巴楚县| 岳阳县| 从江县| 聂荣县| 扶风县| 玉屏| 塔城市| 龙里县| 达日县| 石首市| 江津市|