当前位置: 首页 > news >正文

4. Flink SQL访问HiveCatalog

一. 实验环境
Flink版本: 1.19.1
Hive版本: 2.1.3
Hadoop版本: 3.2.4
二. 操作步骤

1.上传所需的jar包到Flink lib目录下

[root@hadoop3 ~]# mv flink-sql-connector-hive-3.1.3_2.12-1.19.1.jar /www/flink-1.19.1/lib
[root@hadoop3 ~]# mv hadoop-mapreduce-client-core-3.2.4.jar /www/flink-1.19.1/lib
[root@hadoop3 ~]# mv mysql-connector-java-8.0.30.jar /www/flink-1.19.1/lib

2.修改Hive配置文件hive-site.xml

[root@hadoop3 ~]# vim hive-site.xml

# 配置metastore uris
<property>
    <name>hive.metastore.uris</name>
    <value>thrift://hadoop1:9083</value>
    <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>

3.启动Hive外置metastore

[root@hadoop3 ~]# hive --service metastore

3.启动Flink SQL客户端

[root@hadoop3 ~]# yarn-session.sh  -d -nm mysession
[root@hadoop3 ~]# sql-client.sh  -s yarn-session
三. 功能验证

1.Hive创建测试表并插入数据

# 创建测试表
hive> create table t1(id int, name string);
OK
Time taken: 0.106 seconds

# 查看所有表
hive> show tables;
OK
t1
Time taken: 0.056 seconds, Fetched: 1 row(s)

# 插入测试数据
hive> insert into t1 values(1, 'name1'), (2, 'name2');

# 查看测试数据
hive> select * from t1;
OK
1       name1
2       name2
Time taken: 0.229 seconds, Fetched: 2 row(s)

2.Flink创建Catalog并使用

# 创建hive catalog
Flink SQL> CREATE CATALOG myhive WITH (
    'type' = 'hive',
    'default-database' = 'default',
    'hive-conf-dir' = '/www/hive-3.1.3/conf',
	'hadoop-conf-dir'='/www/hadoop-3.2.4/etc/hadoop'
);

3.Flink SQL访问Hive表

Flink SQL> set 'sql-client.execution.result-mode'='tableau';
[INFO] Execute statement succeed.

Flink SQL> show tables;
+------------+
| table name |
+------------+
|         t1 |
+------------+
1 row in set
# 访问hive表数据
Flink SQL> select * from t1;
2025-03-30 10:04:42,897 INFO  org.apache.hadoop.mapred.FileInputFormat                     [] - Total input files to process : 1
2025-03-30 10:04:43,093 WARN  org.apache.flink.yarn.configuration.YarnLogConfigUtil        [] - The configuration directory ('/www/flink-1.19.1/conf') already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file.
2025-03-30 10:04:43,125 INFO  org.apache.hadoop.yarn.client.RMProxy                        [] - Connecting to ResourceManager at hadoop1/10.0.49.4:8032
2025-03-30 10:04:43,126 INFO  org.apache.flink.yarn.YarnClusterDescriptor                  [] - No path for the flink jar passed. Using the location of class org.apache.flink.yarn.YarnClusterDescriptor to locate the jar
2025-03-30 10:04:43,133 INFO  org.apache.flink.yarn.YarnClusterDescriptor                  [] - Found Web Interface hadoop2:43005 of application 'application_1743044623193_0012'.

+----+-------------+--------------------------------+
| op |          id |                           name |
+----+-------------+--------------------------------+
| +I |           1 |                          name1 |
| +I |           2 |                          name2 |
+----+-------------+--------------------------------+
Received a total of 2 rows (4.61 seconds)

相关文章:

  • 营销网站建设的步骤过程网络搭建是干什么的
  • 建设网站目的及功能定位是什么百度怎么做推广
  • 青岛做外贸网站雷神代刷网站推广
  • 建网站的详细案例搜索引擎收录
  • wordpress 调用头像女生做sem还是seo
  • 做外贸网站租什么服务器苏州首页排名关键词优化
  • <em>凤</em><em>凰</em><em>购</em><em>彩</em><em>大</em><em>厅</em>
  • 三个核心文件:src\App.vue文件,index.html文件,src\main.js文件 的关系与运行流程解析(通俗形象)
  • L2-037 包装机 (分数25)(详解)
  • DeepSeek协助优化-GTX750Ti文物显卡0.65秒卷完400MB float 音频512阶时域FIR
  • OTN(Optical Transport Network)详解
  • RK3588,V4l2 读取Gmsl相机, Rga yuv422转换rgb (dma), 实现零拷贝
  • 【Deep Reinforcement Learning Hands-On Third Edition】【序】
  • Python Django基于人脸识别的票务管理系统(附源码,文档说明)
  • 运算放大器(三)运算放大器的典型应用
  • Zoomlt使用
  • 解决:在运行 plt.show()`时,程序会等待你手动关闭图片窗口才能继续往下执行
  • 基于YOLO11/WVP的电梯系统开发-模型训练与rk3568移植
  • HarmonyOS NEXT——【鸿蒙实现录音识别(语音转文字)】
  • Node.js 技术原理分析系列 —— Node.js 调试能力分析
  • 正则化是什么?
  • Anolis OS 8.4修复CVE-1999-0554漏洞记录
  • 操作系统——线程的概念和特点
  • ssm框架之Spring
  • BIM/I-FGSM对抗样本生成算法实现(pytorch版)
  • Java-01-源码篇-JUC并发编程-常用类