(五)springboot 配置多数据源连接mysql和hive

使用Spring Boot开发SparkSQL读取Hive 这是Spring Boot开发SparkSQL读取Hive数据库,并可使用Web接口查询Hive数据的基本步骤。4. 创建一个`@Controller`类,并注入`PersonRepository`类,并添加一个Web接口API,用于呈现查询结果。下面是使用Spring Boot开发SparkSQL读取Hive数据库的代码,并且可以使用Web接口来读取Hive数据的示例。在这里,我们使用`SparkSQL`查询Hive表中的数据。 阅读详情

项目结构如下

mysql 执行如下建表语句,并插入一条测试数据

1

2

3

4

5

CREATE TABLE `user` (

  `id` int(11) NOT NULL,

  `name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

使用hive客户端执行如下建表语句,并插入一条测试数据

1

create table `user` (`id` int, `name` string);

1. 引入依赖 pom.xml如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>

    <artifactId>hadoop-demo</artifactId>

    <version>1.0-SNAPSHOT</version>

    <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <mybatis-spring-boot>1.2.0</mybatis-spring-boot>

        <mysql-connector>8.0.11</mysql-connector>

        <activiti.version>5.22.0</activiti.version>

    </properties>

    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.7.7</version>

    </parent>

    <dependencies>

        <!--springBoot相关-->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->

        <!-- https://mvnrepository.com/artifact/com.baomidou/dynamic-datasource-spring-boot-starter -->

        <dependency>

            <groupId>com.baomidou</groupId>

            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>

            <version>3.6.1</version>

        </dependency>

        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->

        <dependency>

            <groupId>com.baomidou</groupId>

            <artifactId>mybatis-plus-boot-starter</artifactId>

            <version>3.5.3.1</version>

        </dependency>

        <!--mybatis相关-->

        <!--   <dependency>

              <groupId>org.mybatis.spring.boot</groupId>

              <artifactId>mybatis-spring-boot-starter</artifactId>

              <version>${mybatis-spring-boot}</version>

          </dependency>-->

          <!--mysql驱动相关-->

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

            <version>${mysql-connector}</version>

        </dependency>

        <!--druid连接池相关-->

        <dependency>

            <groupId>com.alibaba</groupId>

            <artifactId>druid</artifactId>

            <version>1.1.12</version>

        </dependency>

        <!-- 添加hadoop依赖begin -->

        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->

        <dependency>

            <groupId>org.apache.hadoop</groupId>

            <artifactId>hadoop-common</artifactId>

            <version>3.3.4</version>

        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs -->

        <dependency>

            <groupId>org.apache.hadoop</groupId>

            <artifactId>hadoop-hdfs</artifactId>

            <version>3.3.4</version>

        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->

        <dependency>

            <groupId>org.apache.hadoop</groupId>

            <artifactId>hadoop-client</artifactId>

            <version>3.3.4</version>

        </dependency>

        <!--添加hadoop依赖end -->

        <!-- 添加hive依赖begin -->

        <dependency>

            <groupId>org.apache.hive</groupId>

            <artifactId>hive-jdbc</artifactId>

            <version>3.1.3</version>

            <exclusions>

                <exclusion>

                    <groupId>org.eclipse.jetty.aggregate</groupId>

                    <artifactId>*</artifactId>

                </exclusion>

                <exclusion>

                    <groupId>org.eclipse.jetty</groupId>

                    <artifactId>jetty-runner</artifactId>

                </exclusion>

            </exclusions>

        </dependency>

        <!-- 添加hive依赖end -->

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

        <dependency>

            <groupId>org.projectlombok</groupId>

            <artifactId>lombok</artifactId>

            <version>1.18.24</version>

            <scope>provided</scope>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

            <version>4.12</version>

            <scope>test</scope>

        </dependency>

    </dependencies>

    <build>

        <finalName>community</finalName>

        <resources>

            <resource>

                <directory>src/main/java</directory>

                <includes>

                    <include>**/*.properties</include>

                    <include>**/*.xml</include>

                </includes>

                <filtering>false</filtering>

            </resource>

            <resource>

                <directory>src/main/resources</directory>

                <includes>

                    <include>**/*.*</include>

                </includes>

                <filtering>false</filtering>

            </resource>

        </resources>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

                <configuration>

                    <mainClass>com.mfc.hive.HiveApplication</mainClass>

                    <layout>ZIP</layout>

                    <includeSystemScope>true</includeSystemScope>

                </configuration>

                <executions>

                    <execution>

                        <goals>

                            <goal>repackage</goal>

                        </goals>

                    </execution>

                </executions>

            </plugin>

        </plugins>

    </build>

</project>

2.application-dev.yml 配置如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

server:

  port: 6080

spring:

  application:

    name: hadoop-service

  datasource:

    dynamic:

      primary: master #设置默认的数据源,默认值为master

      strict: false   #是否弃用严格模式,如果启用在味匹配到指定数据源时抛出异常

      datasource:

        master:

          driver-class-name: com.mysql.jdbc.Driver

          type: com.alibaba.druid.pool.DruidDataSource

          url: jdbc:mysql://localhost:3306/hadoop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2b8

          username: root

          password: xxxx

        hive:

          driver-class-name: org.apache.hive.jdbc.HiveDriver

          type: com.alibaba.druid.pool.DruidDataSource

          url: jdbc:hive2://hadoop-master:21000

          username: hadoop

          password:

  druid:

    initialSize: 5 #初始化连接大小

    minIdle: 5     #最小连接池数量

    maxActive: 20  #最大连接池数量

    maxWait: 60000 #获取连接时最大等待时间,单位毫秒

    timeBetweenEvictionRunsMillis: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒

    minEvictableIdleTimeMillis: 300000   #配置一个连接在池中最小生存的时间,单位是毫秒

    validationQuery: SELECT 1 from DUAL  #测试连接

    testWhileIdle: true                  #申请连接的时候检测,建议配置为true,不影响性能,并且保证安全性

    testOnBorrow: false                  #获取连接时执行检测,建议关闭,影响性能

    testOnReturn: false                  #归还连接时执行检测,建议关闭,影响性能

    poolPreparedStatements: false        #是否开启PSCache,PSCache对支持游标的数据库性能提升巨大,oracle建议开启,mysql下建议关闭

    maxPoolPreparedStatementPerConnectionSize: 20 #开启poolPreparedStatements后生效

    filters: stat,wall,log4j #配置扩展插件,常用的插件有=>stat:监控统计  log4j:日志  wall:防御sql注入

    connectionProperties: 'druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000' #通过connectProperties属性来打开mergeSql功能;慢SQL记录

3. 新增HiveController

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

package com.mfc.hive.controller;

import com.mfc.hive.domain.User;

import com.mfc.hive.service.IHiveService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

@RequestMapping("/api/v1/hive")

public class HiveController {

    @Autowired

    private IHiveService hiveService;

    @GetMapping("/mysql")

    public void mysql() {

        List<User> userList = hiveService.mysql();

        int a = 0;

    }

    @GetMapping("/hive")

    public void hive() {

        List<User> userList = hiveService.hive();

        int a = 0;

    }

}

4.新增service接口

1

2

3

4

5

6

7

8

9

10

11

12

package com.mfc.hive.service;

import com.mfc.hive.domain.User;

import java.util.List;

public interface IHiveService {

    List<User> mysql();

    List<User>  hive();

}

5.新增service实现

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

package com.mfc.hive.service.impl;

import com.mfc.hive.dao.mapper.IHiveMapper;

import com.mfc.hive.domain.User;

import com.mfc.hive.service.IHiveService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class HiveServiceImpl implements IHiveService {

    @Autowired

    private IHiveMapper hiveMapper;

    public List<User> mysql() {

        return hiveMapper.mysql();

    }

    public List<User> hive() {

        return hiveMapper.hive();

    }

}

6.新增mapper接口

注意默认数据源为mysql,如需要使用hive数据源可以通过@Ds注解指定,如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

package com.mfc.hive.dao.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;

import com.mfc.hive.domain.User;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository

public interface IHiveMapper {

    List<User> mysql();

    @DS("hive")

    List<User> hive();

}

7.增加mapper配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.mfc.hive.dao.mapper.IHiveMapper">

    <resultMap id="userMap" type="com.mfc.hive.domain.User">

        <id property="id" column="id"/>

        <result property="name" column="name"/>

    </resultMap>

    <select id="mysql" parameterType="String" resultMap="userMap">

        select `id`,`name` from `user`

    </select>

    <select id="hive" parameterType="String" resultMap="userMap">

        select `id`,`name` from `user`

    </select>

</mapper>

8.测试

打开postman选择get方法

8.1调用hive查询user表

输入地址localhost:6080/api/v1/hive/hive

8.2调用mysql查询user表

输入地址localhost:6080/api/v1/hive/mysql

Mybatis-plus4条件构造器方式 【代码】Mybatis-plus4条件构造器方式。 阅读详情

相关推荐

springboot+mybatisplus+druid+hive+mysql.zip

hive

【springboot】连接hive数据库

springboot后台开发连接hive数据库 确保集群上hivesever2的服务已启动 hive数据库一般在10000端口 springboot开发 pox.xml 文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="...

lorogy的博客 7431

电流模架构Bandgap设计与仿真

带隙基准作为集成电路中一个重要模块,被广泛应用在低压差线性稳压(LDO)、充电电池保护芯片和通信电路、射频收发器、flash存储器等多种模拟及数模混合集成电路中,并且是片上集成系统(SOC)芯片中不可或缺的部分,为整个芯片提供精确的电压参考点............

qq_50968231的博客 5万+

spring boot集成hive

文章目录前言一、创建spring boot工程1. 添加hive-jdbc依赖(无需hadoop依赖)2. 添加德鲁伊连接池依赖3. 完整依赖如下二、使用步骤1.配置Druid连接池2. 配置application.yml3. 编写controller进行测试 前言 spring boot集成hive,实现在网页查询hive数据。 非完全原创,参考链接放在下面 原帖的依赖会冲突导致无法运行,本帖修改了一些依赖,并加入了lombok,其余同原帖。 https://blog.youkuaiyun.com/pengj

qq_39344641的博客 7364

MFC停靠窗口实战:CDockablePane从创建到控件布局的完整指南(附残影问题排查)

本文提供了MFC中CDockablePane停靠窗口的完整实战指南,涵盖从自定义窗格类创建、主框架集成、内部控件布局到高级功能定制的全过程。针对开发中常见的“残影”视觉问题,文章深入剖析了其根源,并给出了系统性的排查步骤与解决方案,帮助开发者构建稳定、专业的可停靠用户界面。

sun99的博客 614

SAP ABAP实战:用BAPI_PO_CREATE1创建采购订单时,如何巧妙处理PBXX和PB00条件类型?

本文深入探讨了在SAP ABAP开发中使用BAPI_PO_CREATE1创建采购订单时,如何有效处理PBXX和PB00条件类型的难题。通过分析外协加工订单的特殊需求,提供了从问题定位到解决方案的全流程方法,包括数据流向追踪、字段控制策略和增强实现方案,帮助开发者解决条件类型自动生成的业务痛点。

weixin_30614109的博客 824

SpringBoot多数据源配置(hive/mysql)

简介 在项目实践中,同一个项目可能需要整合多种数据源,把分散到各个数据库、数据表的数据都查询统计出来; SpringBoot有默认的数据源配置,本篇博客将整合SpringBoot多数据源配置,包括mysql、hive等,通过jdbctemplate或mybatis进行使用; 版本配置(版本可自行选择,这里是博主的测试版本):jdk1.8,springboot1.5.9,hive2.1.1,h...

alan_liuyue的博客 1万+

告别激活烦恼:Lattice Diamond 3.13 永久免费License申请与配置全攻略(Windows 64位)

本文详细介绍了Lattice Diamond 3.13永久免费License的申请与配置全流程,特别针对Windows 64位系统用户。从官网导航的隐藏路径到Host ID的获取方式,再到License文件的高级处理技巧和环境变量的深度配置,提供了全面的安装教程和疑难问题解决方案,帮助开发者彻底告别激活烦恼。

weixin_28736335的博客 425

springboot项目多数据源配置,集成hive和mysql

最近做的这个项目,原本数据库是用的mysql,后来需求问题,经过讨论后打算把hive集成进来,就是有一批数据入hive。 经过昨晚的尝试加上上网查阅资料总算是集成好了。 集成好了后的效果就是mysql和hive互不影响可独立使用,而且也不会影响mybatis的 使用,既然集成应该都是要这种效果吧。 代码有点多,不要着急,咱们一步一步的来 第一步pom文件:以下jar如果你已经有了就无需在添...

小栋哟 4522

Meta-RL之Meta-Gradient Reinforcement Learning

这篇文章是用元学习算法去学习RL的超参数η={γ,λ}\eta=\{\gamma,\lambda\}η={γ,λ}。当然不仅限于这2个超参数,还可以是和回报相关的超参数。 本文的核心思想:我们之前接触过Meta-Learning参数的初始化(MAML、Reptile)以及Meta-Learning参数的更新优化(L2L-by-gd-by-gd、Opt as a model for few-shot learning),那么这篇就是能否Meta-Learning到η={γ,λ}\eta=\{\gamma,\l

Ton的博客 2520

【TIDB】TiDB认证考试PTCA 练习题 题库

TiDB认证考试PTCA 练习题 题库

DBA之路的博客 4720

springboot hive mysql 多数据源切换

springboot hive mysql 多数据源切换 本次实验重在多数据源切换 性能不在考虑其中 开发环境: hive 3.1.3 mysql 8.0.33 jdk 1.8 maven 3.9.1 idea 2023.1 springboot 2.7.11 HikariCP 连接池 实验效果:从 hive 中迁移数据到 MySQL pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave

桃李不言下自成蹊 7万+

基于多传感器融合的智身四足机器狗楼梯环境SLAM系统设计与实现

本文设计了一种基于多传感器融合的四足机器狗楼梯环境SLAM系统。系统采用Jetson Orin NX为主控制器,集成RealSense D435i深度相机和Livox Mid360激光雷达,在ROS2框架下实现平面定位精度<5cm、楼梯环境下导航不漂移的目标。通过多层次传感器融合策略、运动学约束优化和状态切换机制,解决了楼梯环境下的定位累积误差问题,实现了平面与楼梯环境的自动识别切换及精度复位功能。硬件设计注重传感器布局优化和精确标定,软件架构采用分层设计,确保实时性能。该系统为四足机器人在复杂地形中

huanghm88的专栏 241

案例: springboot 同时集成hive和mysql

1.配置maven( pom.xml文件 ): 1.1 集成hive: <!-- hive --> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId&...

u010235716的博客 4036

华为OD机试 - 停车场费用统计 - HashSet(Python/JS/C/C++ 双机位C卷 100分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。停车场统计当日总收费,包月的车不统计,不包月的车半个小时收一块钱,不满半小时不收费,如果超过半小时,零头不满半小时按半小时算,每天11:30-13:30时间段不收费,如果一辆车停车时间超过8小时后不收费。现提供停车场进出车辆的统计信息,需要你来计

学Java,找哪吒 238

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

springBoot多数据源配置,如mysql、hive,使用druid连接池

总共需要以下几个类: package com.config.datasource; import com.alibaba.druid.pool.DruidDataSource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springfr

mathlpz126的博客 2002

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

springboot多数据源配置mybatis采用druid连接池对mysql,hive双数据源整合

介绍:在项目开发的过程中我们很少出现单纯的只使用一个数据源,而一般情况我们在一个项目中会用都多个数据源,最近遇到的项目就需要从大数据的数据中拿部分数据,然后自己项目中的一些业务用mysql所以涉及到两个数据源 本例子就讲解如何利用springboot配置hive、mysql、mybatis这样就不需要使用jdbc去连接方便灵活了很多 第一步:首先我们需要下载依赖: maven依赖,包括mybatis,springboot,大数据连接,MySQL依赖,druid等 <pr...

立志欲坚不欲锐,成功在久不在速度 2432

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

springboot 2.* 整合 hive 和 mysql 多数据源配置

话不多说,直接开搞: 添加 POM 的hive 和 mysql 依赖(可能有一些没有用) <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>1.1.0</ver...

转身那一瞬 1895

springboot + mybatis +tkmapper 连接多数据源

1.说明: springboot连接多数据源是大家经常要用到的操作,下面我用springboot连接两个mysql和一个hive,采用的连接池是druid,学会这个后大家可以连接各种多数据源了,采用的操作方式是mybatis,也大致讲述使用jdbc的操作方式 2.步骤(表演来了:我用的是2.1.8版本的springboot) 1.导入相应的jar包 <dependency>...

qq_37497275的博客 2077

Spring-Boot集成MyBatis+Druid实现Hive/MySQL多数据源切换:高效稳定的多数据源解决方案

Spring-Boot集成MyBatis+Druid实现Hive/MySQL多数据源切换:高效稳定的多数据源解决方案 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在现代化的企业级应用开发中,数据的多样性和灵活性要求越来越高。Spring-Boot集成MyBatis和Druid实现Hive/MySQL多数据源切换,正是一个为满足这种需求而生的解决方案。该项目提供了一套...

gitblog_06784的博客 1010

Spring boot 配置多数据源并使用连接池管理 - mysql - hive

1、搭建springboot项目,项目目录如下: 2.部分配置源码如下,不想自己配置的小伙伴可以直接去github下载,github地址:github项目地址: yml配置: spring: datasource: #使用druid连接池 type: com.alibaba.druid.pool.DruidDataSource # 自定义的主数据源配置信息 prim...

mthinking 4748

Spring boot 配置多数据源并使用连接池管理- mysql

1、搭建springboot项目,项目目录如下: 2.部分配置源码如下,yml配置: spring: datasource: #使用druid连接池 type: com.alibaba.druid.pool.DruidDataSource # 自定义的主数据源配置信息 primary: datasource: #druid相关配置 druid: #监控统计拦截的filters filters: stat driverClassNa

weixin_43876684的博客 1833

hive和mysql集成_案例: springboot 同时集成hive和mysql

1.配置maven( pom.xml文件 ):1.1 集成hive:org.apache.hivehive-jdbc1.1.0org.apache.httpcomponentshttpcoreorg.apache.hadoophadoop-commonlog4jlog4jorg.slf4jslf4j-log4j12org.apache.httpcomponentshttpclientcom.goo...

weixin_29797343的博客 873

Springboot+Druid(可切换Hikari)+Mybatis-plus+mysql+hive的多数据源项目配置

Springboot+Druid(可切换Hikari)+Mybatis-plus+mysql+hive的多数据源项目配置

我不会敲代码的博客 1227

Spring-Boot集成MyBatis+Druid实现Hive/MySQL多数据源切换

Spring-Boot集成MyBatis+Druid实现Hive/MySQL多数据源切换 去发现同类优质开源项目:https://gitcode.com/ 此资源文件为一份详细的开发指南,介绍如何在Spring-Boot框架下,通过集成MyBatis和Druid,实现Hive与MySQL之间的多数据源动态切换。本指南利用MySQL数据库作为用户验证库及用户信息库,同时使用Hive作为数据可视化源库...

gitblog_06764的博客 1031

Spring Boot 集成 Hive

按照实际情况配置 MySQL 和 Hive 的地址、端口、账号、密码。其他依赖视个人情况添加。

weixin_45131680的博客 1681
上一篇: ​(四)hive的搭建2
下一篇: 测试工具之压测工具JMeter(一)
调试大师
博客等级 码龄3年 2340粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

调试大师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值