I don't think Broadcast itself can be serialized. you can get the value out
on the driver side and refer to it in foreach, then the value would be
serialized with the lambda expr and sent to workers.

On Fri, Jun 16, 2017 at 2:29 AM, Anton Kravchenko <
kravchenko.anto...@gmail.com> wrote:

> How one would access a broadcasted variable from within
> ForeachPartitionFunction  Spark(2.0.1) Java API ?
>
> Integer _bcv = 123;
> Broadcast<Integer> bcv = spark.sparkContext().broadcast(_bcv);
> Dataset<Row> df_sql = spark.sql("select * from atable");
>
> df_sql.foreachPartition(new ForeachPartitionFunction<Row>() {
>     public void call(Iterator<Row> t) throws Exception {
>         System.out.println(bcv.value());
>     }}
> );
>
>

Reply via email to