【Flink异常】Caused by: org.apache.flink.table.api.ValidationException: Could not find any factories
程序员文章站
2022-04-12 20:31:31
...
1. 异常详情
Exception in thread "main" org.apache.flink.table.api.ValidationException: Could not find any factories that implement 'org.apache.flink.table.factories.FileSystemFormatFactory' in the classpath.
at org.apache.flink.table.factories.FactoryUtil.discoverFactory(FactoryUtil.java:229)
at org.apache.flink.table.filesystem.FileSystemTableFactory.createFormatFactory(FileSystemTableFactory.java:112)
at org.apache.flink.table.filesystem.FileSystemTableSource.getInputFormat(FileSystemTableSource.java:143)
at org.apache.flink.table.filesystem.FileSystemTableSource.getDataStream(FileSystemTableSource.java:127)
at org.apache.flink.table.planner.plan.nodes.physical.PhysicalLegacyTableSourceScan.getSourceTransformation(PhysicalLegacyTableSourceScan.scala:82)
at org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecLegacyTableSourceScan.translateToPlanInternal(BatchExecLegacyTableSourceScan.scala:95)
at org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecLegacyTableSourceScan.translateToPlanInternal(BatchExecLegacyTableSourceScan.scala:57)
at org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58)
2. 原因
原因:使用flink sql中的format参数解析文本时,没有引入相关format依赖
(笔者使用的是flink 1.11版本)。
报错代码:
String sourceSql = "CREATE TABLE url_parse_100 ("
+ " logtime STRING,"
+ " sign STRING,"
+ " version STRING"
+ " ) WITH ( "
+ " 'connector' = 'filesystem',"
+ " 'path' = 'E:/url_parse_100.txt',"
+ " 'format' = 'json'"
+ ")";
System.out.println("执行SQL: " + sourceSql);
tableEnv.executeSql(sourceSql);
上例中format参数值为“json”,因此需要引入flink json模块依赖。
3. 解决办法
根据数据格式引入相应flink format相关依赖。
上例中需要引入的pom依赖为:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-json</artifactId>
<version>1.11.0</version>
</dependency>