Skip to content

Commit 725715c

Browse files
scwfmateiz
authored andcommitted
[SPARK-3010] fix redundant conditional
https://issues.apache.org/jira/browse/SPARK-3010 this pr is to fix redundant conditional in spark, such as 1. private[spark] def codegenEnabled: Boolean = if (getConf(CODEGEN_ENABLED, "false") == "true") true else false 2. x => if (x == 2) true else false ... Author: scwf <wangfei1@huawei.com> Author: wangfei <wangfei_hello@126.com> Closes #1992 from scwf/condition and squashes the following commits: b2a044a [scwf] merge SecurityManager e16239c [scwf] fix confilct 6811401 [scwf] fix merge confilct 0824df4 [scwf] Merge branch 'master' of https://github.com/apache/spark into patch-4 e274515 [scwf] fix redundant conditions d032bf9 [wangfei] [SQL]Excess judgment
1 parent c567a68 commit 725715c

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

core/src/main/scala/org/apache/spark/SecurityManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging {
294294
def checkUIViewPermissions(user: String): Boolean = {
295295
logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " viewAcls=" +
296296
viewAcls.mkString(","))
297-
if (aclsEnabled() && (user != null) && (!viewAcls.contains(user))) false else true
297+
!aclsEnabled || user == null || viewAcls.contains(user)
298298
}
299299

300300
/**
@@ -309,7 +309,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging {
309309
def checkModifyPermissions(user: String): Boolean = {
310310
logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " modifyAcls=" +
311311
modifyAcls.mkString(","))
312-
if (aclsEnabled() && (user != null) && (!modifyAcls.contains(user))) false else true
312+
!aclsEnabled || user == null || modifyAcls.contains(user)
313313
}
314314

315315

core/src/test/scala/org/apache/spark/rdd/PartitionPruningRDDSuite.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext {
3838
Iterator()
3939
}
4040
}
41-
val prunedRDD = PartitionPruningRDD.create(rdd, {
42-
x => if (x == 2) true else false
43-
})
41+
val prunedRDD = PartitionPruningRDD.create(rdd, _ == 2)
4442
assert(prunedRDD.partitions.length == 1)
4543
val p = prunedRDD.partitions(0)
4644
assert(p.index == 0)
@@ -62,13 +60,10 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext {
6260
List(split.asInstanceOf[TestPartition].testValue).iterator
6361
}
6462
}
65-
val prunedRDD1 = PartitionPruningRDD.create(rdd, {
66-
x => if (x == 0) true else false
67-
})
63+
val prunedRDD1 = PartitionPruningRDD.create(rdd, _ == 0)
6864

69-
val prunedRDD2 = PartitionPruningRDD.create(rdd, {
70-
x => if (x == 2) true else false
71-
})
65+
66+
val prunedRDD2 = PartitionPruningRDD.create(rdd, _ == 2)
7267

7368
val merged = prunedRDD1 ++ prunedRDD2
7469
assert(merged.count() == 2)

sql/core/src/main/scala/org/apache/spark/sql/columnar/ColumnType.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ private[sql] object BOOLEAN extends NativeColumnType(BooleanType, 4, 1) {
158158
buffer.put(if (v) 1.toByte else 0.toByte)
159159
}
160160

161-
override def extract(buffer: ByteBuffer) = {
162-
if (buffer.get() == 1) true else false
163-
}
161+
override def extract(buffer: ByteBuffer) = buffer.get() == 1
164162

165163
override def setField(row: MutableRow, ordinal: Int, value: Boolean) {
166164
row.setBoolean(ordinal, value)

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ClientBase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ trait ClientBase extends Logging {
209209
if (! localPath.isEmpty()) {
210210
val localURI = new URI(localPath)
211211
if (!ClientBase.LOCAL_SCHEME.equals(localURI.getScheme())) {
212-
val setPermissions = if (destName.equals(ClientBase.APP_JAR)) true else false
212+
val setPermissions = destName.equals(ClientBase.APP_JAR)
213213
val destPath = copyRemoteFile(dst, qualifyForLocal(localURI), replication, setPermissions)
214214
val destFs = FileSystem.get(destPath.toUri(), conf)
215215
distCacheMgr.addResource(destFs, conf, destPath, localResources, LocalResourceType.FILE,

0 commit comments

Comments
 (0)