How to access objects declared and initialized out

2019-08-10 20:16发布

I am unable to access objects declared and initialized outside the call() method of JavaRDD.
In the below code snippet, call() method makes a fetch call to C* but since javaSparkContext is defined outside the call method scope so compiler give a compilation error.

stringRdd.foreach(new VoidFunction<String>() {
                @Override
                public void call(String str) throws Exception {
                    JavaRDD<String> vals = javaFunctions(javaSparkContext).cassandraTable("schema", "table", String.class)
                            .select("val");
                }
            });

In other languages I have used closure to do this but not able to achieve the same here. Can someone suggest how to achieve this in the current code context.

0条回答
登录 后发表回答