Skip to content

Commit d1fa804

Browse files
committed
[SPARK-7979] Enforce structural type checker.
1 parent f7fe9e4 commit d1fa804

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

core/src/test/scala/org/apache/spark/util/random/XORShiftRandomSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import scala.language.reflectiveCalls
2828

2929
class XORShiftRandomSuite extends SparkFunSuite with Matchers {
3030

31-
def fixture: Object {val seed: Long; val hundMil: Int; val xorRand: XORShiftRandom} = new {
31+
private def fixture = new {
3232
val seed = 1L
3333
val xorRand = new XORShiftRandom(seed)
3434
val hundMil = 1e8.toInt

examples/src/main/scala/org/apache/spark/examples/mllib/DecisionTreeRunner.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ import scala.language.reflectiveCalls
2222
import scopt.OptionParser
2323

2424
import org.apache.spark.{SparkConf, SparkContext}
25-
import org.apache.spark.SparkContext._
2625
import org.apache.spark.mllib.evaluation.MulticlassMetrics
27-
import org.apache.spark.mllib.linalg.Vector
2826
import org.apache.spark.mllib.regression.LabeledPoint
2927
import org.apache.spark.mllib.tree.{DecisionTree, RandomForest, impurity}
3028
import org.apache.spark.mllib.tree.configuration.{Algo, Strategy}
3129
import org.apache.spark.mllib.tree.configuration.Algo._
30+
import org.apache.spark.mllib.tree.model.DecisionTreeModel
3231
import org.apache.spark.mllib.util.MLUtils
3332
import org.apache.spark.rdd.RDD
3433
import org.apache.spark.util.Utils
@@ -354,7 +353,11 @@ object DecisionTreeRunner {
354353

355354
/**
356355
* Calculates the mean squared error for regression.
356+
*
357+
* This is just for demo purpose. In general, don't copy this code because it is no very efficient
358+
* due to the use of structural types, which leads to one reflection call per record.
357359
*/
360+
// scalastyle:off structural.type
358361
private[mllib] def meanSquaredError(
359362
model: { def predict(features: Vector): Double },
360363
data: RDD[LabeledPoint]): Double = {
@@ -363,4 +366,5 @@ object DecisionTreeRunner {
363366
err * err
364367
}.mean()
365368
}
369+
// scalastyle:on structural.type
366370
}

graphx/src/main/scala/org/apache/spark/graphx/EdgeRDD.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ abstract class EdgeRDD[ED](
4141
@transient sc: SparkContext,
4242
@transient deps: Seq[Dependency[_]]) extends RDD[Edge[ED]](sc, deps) {
4343

44+
// scalastyle:off structural.type
4445
private[graphx] def partitionsRDD: RDD[(PartitionID, EdgePartition[ED, VD])] forSome { type VD }
46+
// scalastyle:on structural.type
4547

4648
override protected def getPartitions: Array[Partition] = partitionsRDD.partitions
4749

4850
override def compute(part: Partition, context: TaskContext): Iterator[Edge[ED]] = {
4951
val p = firstParent[(PartitionID, EdgePartition[ED, _])].iterator(part, context)
5052
if (p.hasNext) {
51-
p.next._2.iterator.map(_.copy())
53+
p.next()._2.iterator.map(_.copy())
5254
} else {
5355
Iterator.empty
5456
}

mllib/src/main/scala/org/apache/spark/ml/classification/OneVsRest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ import org.apache.spark.storage.StorageLevel
3737
*/
3838
private[ml] trait OneVsRestParams extends PredictorParams {
3939

40+
// scalastyle:off structural.type
4041
type ClassifierType = Classifier[F, E, M] forSome {
4142
type F
4243
type M <: ClassificationModel[F, M]
4344
type E <: Classifier[F, E, M]
4445
}
46+
// scalastyle:on structural.type
4547

4648
/**
4749
* param for the base binary classifier that we reduce multiclass classification into.

scalastyle-config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
<!-- <parameter name="maximum"><![CDATA[10]]></parameter> -->
115115
<!-- </parameters> -->
116116
<!-- </check> -->
117+
118+
<check level="error" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
119+
117120
<check level="error" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
118121
<check level="error" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="false"></check>
119122
<check level="error" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">

0 commit comments

Comments
 (0)