Flinksql ----HiveCatalog
Posted wudonglianga
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flinksql ----HiveCatalog相关的知识,希望对你有一定的参考价值。
1. 理解
1.JdbcCatalog 使得用户可以将Flink通过JDBC协议连接到关系数据库。
2. PostgresCatalog 是当前实现的唯一一种JDBC Catalog
2. 需要引入的依赖
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-hive_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<!-- Hive Dependency -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.2</version>
</dependency>
需要添加的 hive-site.xml
文件
3.实现
package com.wudl.flink.sql;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;
/**
* @ClassName : Flink_Sql_HiveCatalog
* @Description : Flink 操作HiveCatalog
* @Author :wudl
* @Date: 2021-08-20 21:50
*/
public class Flink_Sql_HiveCatalog {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
// 1. 创建HiveCatalog
HiveCatalog hiveCatalog = new HiveCatalog("myHive", "db_wudl", "wudl-flink-12/input");
//2.注册HiveCatalog
tableEnv.registerCatalog("myHive", hiveCatalog);
//4.使用HiveCatalog
tableEnv.useCatalog("myHive");
// tableEnv.executeSql("select * from dept_copy ").print();
tableEnv.executeSql("select * from db_wudl.dept").print();
System.out.println("---------------------------------------");
// TableResult tableResult = tableEnv.executeSql("select * from db_wudl.dept");
// System.out.println(tableResult.getJobClient().get().getJobStatus());
// tableEnv.executeSql("CREATE TABLE IF NOT EXISTS db_wudl.dept_copy ( deptno INT, dname string, loc INT ) 'ROW' format delimited FIELDS TERMINATED BY '\\t'");
// tableEnv.executeSql("insert into dept_copy select deptno, dname, loc from dept");
}
}
以上是关于Flinksql ----HiveCatalog的主要内容,如果未能解决你的问题,请参考以下文章
95-910-142-源码-FlinkSQL-FlinkSQL追加模式与缩进模式区别
flinksql的 / 的结果只会保留整数部分,flinksql 不支持 div运算符。hive mysql : / 结果是小数, div 结果只会保留整数部分