java编写flink连接kafka常见问题总结

文章目录

  • 控制台输出问题
  • 没有执行计划问题
  • 不能执行
  • sql问题
  • 动态表转为动态流问题

控制台输出问题

问题描述
代码运行一会就结束,没有错误提示,也没有运行结果

解决方法

两种情况

第一种日志没配好
添加依赖

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>

在resources下创建resource bund文件,加入以下代码,命名log4j2.properties

################################################################################
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

rootLogger.level = info
rootLogger.appenderRef.console.ref = ConsoleAppender

logger.sink.name = org.apache.flink.walkthrough.common.sink.AlertSink
logger.sink.level = INFO

appender.console.name = ConsoleAppender
appender.console.type = CONSOLE
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n

第二种,任务没有执行,在代码最后加上

  try {
            env.execute(“jobname”);
        } catch (Exception e) {
            e.printStackTrace();
        }

没有执行计划问题

问题描述
Exception in thread “main” org.apache.flink.table.api.TableException: Could not instantiate the executor. Make sure a planner module is on the classpath

Could not find a suitable table factory for ‘org.apache.flink.table.delegation.ExecutorFactory’ in

解决方法
添加依赖

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table-planner-blink_${scala.binary.version}</artifactId>
            <version>${flink.version}</version>
        </dependency>

不能执行

问题描述
No ExecutorFactory found to execute the application.
解决方法
加入依赖

       <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_${scala.binary.version}</artifactId>
            <version>${flink.version}</version>
        </dependency>

sql问题

问题描述
Exception in thread “main” org.apache.flink.table.api.SqlParserException: SQL parse failed. Encountered “start” at line 1, column 87.
Was expecting one of:

解决方法
1.看sql某些字段,语句,函数有没有问题,缺字母或少字母

2.关键字冲突,字段与java或者sql上的关键字冲突,无法解析,像以上情况,将start改成starts就OK了

动态表转为动态流问题

问题描述
Exception in thread “main” org.apache.flink.table.api.ValidationException: Column types of query result and sink for unregistered table do not match.
Cause: Different number of columns.

Query schema: [starts: STRING, ends: STRING, eventDate: STRING, name: STRING, age: INT]
Sink schema: [f0: RAW(‘com.hehe.bean.Timetest’, ?)]

解决方法

DataStream<Timetest> dd = tableenv.toAppendStream(table, Timetest.class);

提示报错是动态表转为动态流那一行,定位问题在table上和要转化的类上

table的表结构是否是自己想要的字段,可以通过table.printSchema();语句查看

看要转换的类,各变量的get方法是否都存在,此处就是因为少了一个age的get方法因此转换不成想要的类

你可能感兴趣的:(Hadoop,flink,java)