Skip to content

Commit 40f3fc1

Browse files
committed
Mark LongSQLMetric private[metric] to avoid using incorrectly and leak memory
1 parent b1b9071 commit 40f3fc1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private[sql] class IntSQLMetricValue(private var _value: Int) extends SQLMetricV
8181
* A specialized long Accumulable to avoid boxing and unboxing when using Accumulator's
8282
* `+=` and `add`.
8383
*/
84-
private[sql] class LongSQLMetric(name: String)
84+
private[sql] class LongSQLMetric private[metric](name: String)
8585
extends SQLMetric[LongSQLMetricValue, Long](name, LongSQLMetricParam) {
8686

8787
override def +=(term: Long): Unit = {

sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream,
2222
import org.apache.spark.SparkFunSuite
2323
import org.apache.spark.sql.catalyst.InternalRow
2424
import org.apache.spark.sql.catalyst.expressions._
25-
import org.apache.spark.sql.execution.metric.LongSQLMetric
25+
import org.apache.spark.sql.execution.metric.SQLMetrics
26+
import org.apache.spark.sql.test.TestSQLContext
2627
import org.apache.spark.sql.types.{IntegerType, StructField, StructType}
2728
import org.apache.spark.util.collection.CompactBuffer
2829

@@ -36,7 +37,7 @@ class HashedRelationSuite extends SparkFunSuite {
3637

3738
test("GeneralHashedRelation") {
3839
val data = Array(InternalRow(0), InternalRow(1), InternalRow(2), InternalRow(2))
39-
val numDataRows = new LongSQLMetric("data")
40+
val numDataRows = SQLMetrics.createLongMetric(TestSQLContext.sparkContext, "data")
4041
val hashed = HashedRelation(data.iterator, numDataRows, keyProjection)
4142
assert(hashed.isInstanceOf[GeneralHashedRelation])
4243

@@ -52,7 +53,7 @@ class HashedRelationSuite extends SparkFunSuite {
5253

5354
test("UniqueKeyHashedRelation") {
5455
val data = Array(InternalRow(0), InternalRow(1), InternalRow(2))
55-
val numDataRows = new LongSQLMetric("data")
56+
val numDataRows = SQLMetrics.createLongMetric(TestSQLContext.sparkContext, "data")
5657
val hashed = HashedRelation(data.iterator, numDataRows, keyProjection)
5758
assert(hashed.isInstanceOf[UniqueKeyHashedRelation])
5859

@@ -72,7 +73,7 @@ class HashedRelationSuite extends SparkFunSuite {
7273
test("UnsafeHashedRelation") {
7374
val schema = StructType(StructField("a", IntegerType, true) :: Nil)
7475
val data = Array(InternalRow(0), InternalRow(1), InternalRow(2), InternalRow(2))
75-
val numDataRows = new LongSQLMetric("data")
76+
val numDataRows = SQLMetrics.createLongMetric(TestSQLContext.sparkContext, "data")
7677
val toUnsafe = UnsafeProjection.create(schema)
7778
val unsafeData = data.map(toUnsafe(_).copy()).toArray
7879

0 commit comments

Comments
 (0)