我need to use SparkContext instead of JavaSparkContext for the accumulableCollection (if you don't agree check out the linked question並回答它,請)Java在Spark中的Scala Seq?
澄清問題:SparkContext有Java,但希望Scala的序列。我如何讓它開心 - 在Java中?
我有這段代碼做一個簡單的jsc.parallelize
我用JavaSparkContext,但SparkContext想要一個Scala集合。我在這裏想到了我正在構建一個Scala範圍並將其轉換爲Java列表,不知道如何讓核心範圍成爲Scala Seq,這就是parallelize from SparkContext is asking for。
// The JavaSparkContext way, was trying to get around MAXINT limit, not the issue here
// setup bogus Lists of size M and N for parallelize
//List<Integer> rangeM = rangeClosed(startM, endM).boxed().collect(Collectors.toList());
//List<Integer> rangeN = rangeClosed(startN, endN).boxed().collect(Collectors.toList());
錢線是下一個,我如何創建一個Java中的Scala Seq來並行化?
// these lists above need to be scala objects now that we switched to SparkContext
scala.collection.Seq<Integer> rangeMscala = scala.collection.immutable.List(startM to endM);
// setup sparkConf and create SparkContext
... SparkConf setup
SparkContext jsc = new SparkContext(sparkConf);
RDD<Integer> dataSetMscala = jsc.parallelize(rangeMscala);
我正在看[JavaConversions](http://docs.scala-lang.org/overviews/collections/conversions-between-java-and-scala-collections)對象,看起來像它在兩個方向工作,在Java中還是在斯卡拉? – JimLohse
我懷疑你可以在Java中創建一個'Seq',因爲它是'trait',並且在Java中沒有等價物。我認爲在Scala中使用'JavaConversions'是正確的方法。 – davidshen84
我想也許我正在複製[this](http://stackoverflow.com/questions/35988315/convert-java-list-to-scala-seq?rq=1),我會嘗試解決方案,並會發佈一個回答如果它的工作,似乎像JavaConversion可以在Java中使用,如果我正確讀取此:http://stackoverflow.com/questions/35988315/convert-java-list-to-scala-seq?rq=1 – JimLohse