import java.util.Collection;
import org.apache.flink.api.common.functions.MapFunction; import org.apache.flink.configuration.Configuration; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<Integer> toBroadcast = env.fromElements(1, 2, 3); DataSet<String> data = env.fromElements("a", "b"); data.map(new MapFunction<String, String>() { @Override public void open(Configuration parameters) throws Exception { // 3. Access the broadcasted DataSet as a Collection Collection<Integer> broadcastSet = getRuntimeContext().getBroadcastVariable("broadcastSetName"); } @Override public String map(String value) throws Exception { return "hager"; } }).withBroadcastSet(toBroadcast, "broadcastSetName"); display error cannot find symbol Collection<Integer> broadcastSet = getRuntimeContext().getBroadcastVariable("broadcastSetName"); symbol: method getRuntimeContext() method does not override or implement a method from a supertype @Override |
Hi, you should use RichMapFunction not MapFunction. The difference between
RichMapFunction and MapFunction is described in Flink documentation [1]. Regards, Chiwan Park [1] https://ci.apache.org/projects/flink/flink-docs-master/apis/programming_guide.html#rich-functions > On Jul 12, 2015, at 7:51 AM, hagersaleh <[hidden email]> wrote: > > import java.util.Collection; > import org.apache.flink.api.common.functions.MapFunction; > import org.apache.flink.configuration.Configuration; > import org.apache.flink.api.java.DataSet; > import org.apache.flink.api.java.ExecutionEnvironment; > > > ExecutionEnvironment env = > ExecutionEnvironment.getExecutionEnvironment(); > > DataSet<Integer> toBroadcast = env.fromElements(1, 2, 3); > > DataSet<String> data = env.fromElements("a", "b"); > data.map(new MapFunction<String, String>() { > @Override > public void open(Configuration parameters) throws Exception { > // 3. Access the broadcasted DataSet as a Collection > Collection<Integer> broadcastSet = > getRuntimeContext().getBroadcastVariable("broadcastSetName"); > } > > > @Override > public String map(String value) throws Exception { > return "hager"; > } > > }).withBroadcastSet(toBroadcast, "broadcastSetName"); > > > display error > cannot find symbol > Collection<Integer> broadcastSet = > getRuntimeContext().getBroadcastVariable("broadcastSetName"); > symbol: method getRuntimeContext() > > method does not override or implement a method from a supertype > @Override > > > > -- > View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/error-when-use-Broadcast-Variables-cannot-find-symbol-getRuntimeContext-tp2010.html > Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |