Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class SQLMetric(val metricType: String, initValue: Long = 0L) extends Accumulato

override def merge(other: AccumulatorV2[Long, Long]): Unit = other match {
case o: SQLMetric =>
if (_value < 0) _value = 0
if (o.value > 0) _value += o.value
if (o.value > 0) {
if (_value < 0) _value = 0
_value += o.value
}
case _ => throw QueryExecutionErrors.cannotMergeClassWithOtherClassError(
this.getClass.getName, other.getClass.getName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2156,8 +2156,15 @@ class AdaptiveQueryExecSuite
assert(aqeReads.length == 2)
aqeReads.foreach { c =>
val stats = c.child.asInstanceOf[QueryStageExec].getRuntimeStatistics
assert(stats.sizeInBytes >= 0)
val rowCount = stats.rowCount.get
assert(stats.rowCount.get >= 0)
if (rowCount == 0) {
// For empty relation, the query stage doesn't serialize any bytes.
// The SQLMetric keeps initial value.
assert(stats.sizeInBytes == -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

} else {
assert(stats.sizeInBytes > 0)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ class SQLMetricsSuite extends SharedSparkSession with SQLMetricsTestUtils

testMetricsInSparkPlanOperator(exchanges.head,
Map("dataSize" -> 3200, "shuffleRecordsWritten" -> 100))
testMetricsInSparkPlanOperator(exchanges(1), Map("dataSize" -> 0, "shuffleRecordsWritten" -> 0))
// `testData2.filter($"b" === 0)` is an empty relation.
// The exchange doesn't serialize any bytes.
// The SQLMetric keeps initial value.
testMetricsInSparkPlanOperator(exchanges(1),
Map("dataSize" -> -1, "shuffleRecordsWritten" -> 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we show in the SQL UI? printing -1 as the size is a bit weird.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think -1 will be filtered out.

}

test("Add numRows to metric of BroadcastExchangeExec") {
Expand Down