diff options
author | wangyang <wangyang@haizhi.com> | 2016-06-10 13:10:03 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2016-06-10 13:10:03 -0700 |
commit | 026eb90644be7685971dacaabae67a293edd0133 (patch) | |
tree | cacc1ed1fb398d122bb5a46fd20b94574203fd58 /sql/core | |
parent | 865ec32dd997e63aea01a871d1c7b4947f43c111 (diff) | |
download | spark-026eb90644be7685971dacaabae67a293edd0133.tar.gz spark-026eb90644be7685971dacaabae67a293edd0133.tar.bz2 spark-026eb90644be7685971dacaabae67a293edd0133.zip |
[SPARK-15875] Try to use Seq.isEmpty and Seq.nonEmpty instead of Seq.length == 0 and Seq.length > 0
## What changes were proposed in this pull request?
In scala, immutable.List.length is an expensive operation so we should
avoid using Seq.length == 0 or Seq.lenth > 0, and use Seq.isEmpty and Seq.nonEmpty instead.
## How was this patch tested?
existing tests
Author: wangyang <wangyang@haizhi.com>
Closes #13601 from yangw1234/isEmpty.
Diffstat (limited to 'sql/core')
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/SortAggregateExec.scala | 4 | ||||
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/SortAggregateExec.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/SortAggregateExec.scala index 17126519eb..05dbacf07a 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/SortAggregateExec.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/SortAggregateExec.scala @@ -56,8 +56,8 @@ case class SortAggregateExec( override def requiredChildDistribution: List[Distribution] = { requiredChildDistributionExpressions match { - case Some(exprs) if exprs.length == 0 => AllTuples :: Nil - case Some(exprs) if exprs.length > 0 => ClusteredDistribution(exprs) :: Nil + case Some(exprs) if exprs.isEmpty => AllTuples :: Nil + case Some(exprs) if exprs.nonEmpty => ClusteredDistribution(exprs) :: Nil case None => UnspecifiedDistribution :: Nil } } diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala index e63c7c581e..edfdf7cd6b 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala @@ -113,7 +113,7 @@ private[sql] object SQLMetrics { val validValues = values.filter(_ >= 0) val Seq(sum, min, med, max) = { - val metric = if (validValues.length == 0) { + val metric = if (validValues.isEmpty) { Seq.fill(4)(0L) } else { val sorted = validValues.sorted |