flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian <...@apache.org>
Subject Re: Difference between using a global variable and broadcasting a variable
Date Sun, 26 Apr 2015 07:54:56 GMT
Hi Hung,

A broadcast variable can also refer to an intermediate result of a Flink 
computation.

Best,
Sebastian

On 25.04.2015 21:10, HungChang wrote:
> Hi,
>
> What would be the difference between using global variable and broadcasting
> it?
>
> A toy example:
>
> // Using global
> {{...
> private static int num = 10;
> }
>
> public class DivByTen implements FlatMapFunction<Tuple1&lt;Double>,
> Tuple1<Double>> {
>    @Override
>    public void flatMap(Tuple1<Double>value, Collector<Tuple1&lt;Double>>
out)
> {
>       out.collect(new Tuple1<Double>(value/ num));
>    }
> }}
>
> // Using broadcasting :
> {...
> public static class DivByTen extends
> 			RichGMapFunction<Tuple1&lt;Double>, Tuple1<Double>>{
>
> 		private long num;
>
> 		@Override
> 		public void open(Configuration parameters) throws Exception {
> 			super.open(parameters);
> 			num = getRuntimeContext().<Integer> getBroadcastVariable(
> 					"num").get(0);
> 		}
>
> 		@Override
> 		public void map(Tuple1<Double>value, Collector<Tuple1&lt;Double>>
out))
> throws Exception{			
> 			out.collect(new Tuple1<Double>(value/num));
> 		}
> 	}
> }
>
> Best regards,
>
> Hung
>
>
>
> --
> View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/Difference-between-using-a-global-variable-and-broadcasting-a-variable-tp1128.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.
>

Mime
View raw message