How to access objects declared and initialized outside the call() method of JavaRDD

我的梦境 提交于 2019-12-11 11:06:40

问题


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.

来源:https://stackoverflow.com/questions/26517621/how-to-access-objects-declared-and-initialized-outside-the-call-method-of-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!