7.9DStreamin实例输出操作
1. 创建数据库和表
mysql>create database spark;
mysql>use spark;
mysql>create table searchKeyWord(insert_time date, keyword varchar(30),
>search_count integer);
2. 导入依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
3. 创建Scala类,实现热词排序
在spark_chapter07项目的/src/main/scala/cn.itcast.dstream文件夹下,创建一个名为“HotWordBySort”的Scala类,用于编写Spark Streaming应用程序,实现热词统计排序,
4 运行Scala类,并在hadoop01 9999端口输入数据
[root@hadoop01 servers]# nc -lk 9999
hadoop,111
spark,222
hadoop,222
hadoop,222
hive,222
hive,333
Last modified: Friday, 29 October 2021, 1:11 PM