我的方法: -为什么我的自定义函数的调用方法中的println语句不会出现在日志中?
private static Function<ConsumerRecord<String, String>, StreamDataWrapper> createFunction(){
System.out.println("***** inside create function ******");
ObjectMapper mapper = new ObjectMapper();
Function<ConsumerRecord<String, String>, StreamDataWrapper> function = new Function<ConsumerRecord<String, String>, StreamDataWrapper>(){
public StreamDataWrapper call(ConsumerRecord<String, String> c) throws JsonParseException, JsonMappingException, IOException{
System.out.println("**** inside call of Function *******");
System.out.println("**** Consumer record "+c);
StreamData sd = mapper.readValue(c.value(), StreamData.class);
System.out.println("**** StreamData "+sd);
StreamDataWrapper sw = new StreamDataWrapper(sd);
System.out.println("**** StreamDataWrapper "+sw);
return sw;
}
};
System.out.println("***** End of create function ******");
return function;
}
我打电话这个createFunction()
从另一种方法,但问题是,它执行所有语句,但不statements inside call()
。这里是我的方法的output
。 O/P: -
***** inside create function ******
***** End of create function ******
它不打印其他输出语句。 以下是我使用
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.1</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
如何以及从哪里使用createFunction()中的'function'? –
'JavaRDD streamDataRdd = rdd.map(createFunction());' –
Sat
然后呢?什么是将触发你的函数调用的动作? –