Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/11105#discussion_r86484498
--- Diff:
core/src/test/scala/org/apache/spark/DataPropertyAccumulatorSuite.scala ---
@@ -0,0 +1,383 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark
+
+import scala.concurrent.ExecutionContext.Implicits.global
+import scala.ref.WeakReference
+
+import org.scalatest.Matchers
+
+import org.apache.spark.scheduler._
+import org.apache.spark.util.{AccumulatorContext, AccumulatorMetadata,
AccumulatorV2, LongAccumulator}
+
+
+class DataPropertyAccumulatorSuite extends SparkFunSuite with Matchers
with LocalSparkContext {
+ test("two partition old and new") {
+ sc = new SparkContext("local[2]", "test")
+ val acc = sc.longAccumulator(dataProperty = true, "l2")
+
+ val a = sc.parallelize(1 to 20, 2)
+ val b = a.map{x => acc.add(x); x}
+ b.cache()
+ b.count()
+ acc.value should be (210)
+ }
+
+ test("single partition") {
+ sc = new SparkContext("local[2]", "test")
+ val acc = sc.longAccumulator(dataProperty = true)
+
+ val a = sc.parallelize(1 to 20, 1)
+ val b = a.map{x => acc.add(x); x}
+ b.cache()
+ b.count()
+ acc.value should be (210)
+ }
+
+ test("adding only the first element per partition should work even if
partition is empty") {
+ sc = new SparkContext("local[2]", "test")
+ val acc = sc.longAccumulator(dataProperty = true)
+ val a = sc.parallelize(1 to 20, 30)
+ val b = a.mapPartitions{itr =>
+ acc.add(1)
+ itr
+ }
+ b.count()
+ acc.value should be (30)
+ }
+
+ test("shuffled (combineByKey)") {
+ sc = new SparkContext("local[2]", "test")
+ val a = sc.parallelize(1L to 40L, 5)
+ val buckets = 4
+ val b = a.map{x => ((x % buckets), x)}
+ val inputs = List(b, b.repartition(10), b.partitionBy(new
HashPartitioner(5))).map(_.cache())
+ val mapSideCombines = List(true, false)
+ inputs.foreach { input =>
+ mapSideCombines.foreach { mapSideCombine =>
+ val accs = (1 to 4).map(x => sc.longAccumulator(dataProperty =
true)).toList
+ val raccs = (1 to 4).map(x => sc.longAccumulator(dataProperty =
false)).toList
+ val List(acc, acc1, acc2, acc3) = accs
+ val List(racc, racc1, racc2, racc3) = raccs
+ val c = input.combineByKey(
+ (x: Long) => {acc1.add(1); acc.add(1); racc1.add(1);
racc.add(1); x},
+ {(a: Long, b: Long) => acc2.add(1); acc.add(1); racc2.add(1);
racc.add(1); (a + b)},
+ {(a: Long, b: Long) => acc3.add(1); acc.add(1); racc3.add(1);
racc.add(1); (a + b)},
+ new HashPartitioner(10),
+ mapSideCombine)
+ val d = input.combineByKey(
+ (x: Long) => {acc1.add(1); acc.add(1); x},
+ {(a: Long, b: Long) => acc2.add(1); acc.add(1); (a + b)},
+ {(a: Long, b: Long) => acc3.add(1); acc.add(1); (a + b)},
+ new HashPartitioner(2),
+ mapSideCombine)
+ val e = d.map{x => acc.add(1); x}
--- End diff --
related to the discussion about the iterator wrapping in ShuffledRDD --
this looks like the only test case that is related to the chaining of a
shufflerdd plus another rdd.map, both with data accumulators. Is this case
sufficient?
I think it is sufficient, though its not totally obvious to me, at least.
If it didn't work, than after the call to `d.count()`, when you later do
`e.count()`, the updates from `e` would look like they were duplicate updates
from `d` and get ignored. does that sounds right?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]