FlinkSQL Unable to create a source for reading table 'default_catalog.default_database.xxx'

问题描述

使用 FlinkSql 的 jdbc 连接器 读取 mysql 的一张表,总是提示 

Exception in thread "main" org.apache.flink.table.api.ValidationException: Unable to create a source for reading table 'default_catalog.default_database

程序代码

    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(4);
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
        tableEnv.executeSql("CREATE TABLE dim_dic (\n" +
                "  dic_id STRING,\n" +
                "  dic_desc STRING,\n" +
                "  update_time STRING,\n" +
                "  PRIMARY KEY (dic_id) NOT ENFORCED \n" +
                ") WITH (\n" +
                "   'connector' = 'jdbc',\n" +
                "   'url' = 'jdbc:mysql://hostname:3306/db',\n" +
                "   'table-name' = 'dim_dic',\n" +
                "   'username' = 'username',\n" +
                "   'password' = 'pwd----'\n" +
                ")");
        tableEnv.executeSql("select * from dim_dic ").print();
    }

解决方式

仔细看了下SQL无误,再次查看官网发现少了依赖

<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-connector-jdbc -->
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-jdbc</artifactId>
    <version>3.1.1-1.17</version>
    <scope>provided</scope>
</dependency>

 

posted @ 2024-04-03 17:13  晓枫的春天  阅读(1291)  评论(0编辑  收藏  举报