Flink错误:java.lang.NoSuchMethodError: org.apache.flink网站.api.table.table表格


0

我尝试使用flink的table和sqlapi作为一个简单的示例,在这个示例中,我从文件中读取字符串,将其 transformation为Tuple2并尝试将其插入表中。这是 我的代码。

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.table.StreamTableEnvironment;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.table.Table;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class table_streaming_test
{
public static void main (String[] args) throws Exception
{
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); //create execution environment
StreamTableEnvironment tEnv= StreamTableEnvironment.getTableEnvironment(env);
env.setParallelism(1);
DataStream<String> datastream_in= env.readTextFile("file:/home/rishikesh/new_workspace1/table_streaming/stocks.txt");
DataStream<Tuple2<String,Integer>> ds= datastream_in
.flatMap(new Splitter()); // transformation flatmap
Table msg=tEnv.fromDataStream(ds).as("symbol,price");
Table result = msg.select("symbol ='A'");
DataStream<String> ds2 =tEnv.toDataStream(result, String.class);
ds2.print();
env.execute();
}
public static class Splitter implements FlatMapFunction<String, Tuple2<String, Integer>> {
public void flatMap(String sentence, Collector<Tuple2<String, Integer>> out) throws Exception {
String[] token= sentence.split(",");
out.collect(new Tuple2<String, Integer>(token[0],Integer.parseInt(token[1])));
}
}
}

错误如下:(发生在DataStreamds2行=tEnv.toDataStream公司(结果,字符串.class); )

log4j:WARN No appenders could be found for logger (org.apache.flink.api.java.typeutils.TypeExtractor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.flink.api.table.Table.<init>(Lorg/apache/flink/api/table/TableEnvironment;Lorg/apache/flink/api/table/plan/logical/LogicalNode;)V
    at org.apache.flink.api.table.StreamTableEnvironment.ingest(StreamTableEnvironment.scala:97)
    at org.apache.flink.api.java.table.StreamTableEnvironment.fromDataStream(StreamTableEnvironment.scala:61)
    at table_streaming_test.main(table_streaming_test.java:87)

包含的Jar文件包括:

    Flink-dist_2.10-1.1.3.jar

JavaSE-1.7版

2 答案


0

错误的一个可能原因”java.lang.NoSuchMethodError当你使用的flink版本与你在系统上安装的版本不同时。

对我来说,我有Flink1.4.2,我使用的版本是1.3.2。所以我更新了我的pom文件,使其具有相同的版本,并且运行良好。


0

我认为你需要使用阴影插件,并遵循这一步来解决问题

https://ci.apache.org/projects/flink/flink-docs-release-1.4/monitoring/debugging_classloading.html#解析-使用maven shade插件与flink的依赖性冲突


我来回答

写文章

提问题

面试题