Skip to content
Snippets Groups Projects
Commit 725715cb authored by scwf's avatar scwf Committed by Matei Zaharia
Browse files

[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
parent c567a68a
No related branches found
No related tags found
No related merge requests found
...@@ -294,7 +294,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging { ...@@ -294,7 +294,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging {
def checkUIViewPermissions(user: String): Boolean = { def checkUIViewPermissions(user: String): Boolean = {
logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " viewAcls=" + logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " viewAcls=" +
viewAcls.mkString(",")) viewAcls.mkString(","))
if (aclsEnabled() && (user != null) && (!viewAcls.contains(user))) false else true !aclsEnabled || user == null || viewAcls.contains(user)
} }
/** /**
...@@ -309,7 +309,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging { ...@@ -309,7 +309,7 @@ private[spark] class SecurityManager(sparkConf: SparkConf) extends Logging {
def checkModifyPermissions(user: String): Boolean = { def checkModifyPermissions(user: String): Boolean = {
logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " modifyAcls=" + logDebug("user=" + user + " aclsEnabled=" + aclsEnabled() + " modifyAcls=" +
modifyAcls.mkString(",")) modifyAcls.mkString(","))
if (aclsEnabled() && (user != null) && (!modifyAcls.contains(user))) false else true !aclsEnabled || user == null || modifyAcls.contains(user)
} }
......
...@@ -38,9 +38,7 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext { ...@@ -38,9 +38,7 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext {
Iterator() Iterator()
} }
} }
val prunedRDD = PartitionPruningRDD.create(rdd, { val prunedRDD = PartitionPruningRDD.create(rdd, _ == 2)
x => if (x == 2) true else false
})
assert(prunedRDD.partitions.length == 1) assert(prunedRDD.partitions.length == 1)
val p = prunedRDD.partitions(0) val p = prunedRDD.partitions(0)
assert(p.index == 0) assert(p.index == 0)
...@@ -62,13 +60,10 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext { ...@@ -62,13 +60,10 @@ class PartitionPruningRDDSuite extends FunSuite with SharedSparkContext {
List(split.asInstanceOf[TestPartition].testValue).iterator List(split.asInstanceOf[TestPartition].testValue).iterator
} }
} }
val prunedRDD1 = PartitionPruningRDD.create(rdd, { val prunedRDD1 = PartitionPruningRDD.create(rdd, _ == 0)
x => if (x == 0) true else false
})
val prunedRDD2 = PartitionPruningRDD.create(rdd, {
x => if (x == 2) true else false val prunedRDD2 = PartitionPruningRDD.create(rdd, _ == 2)
})
val merged = prunedRDD1 ++ prunedRDD2 val merged = prunedRDD1 ++ prunedRDD2
assert(merged.count() == 2) assert(merged.count() == 2)
......
...@@ -158,9 +158,7 @@ private[sql] object BOOLEAN extends NativeColumnType(BooleanType, 4, 1) { ...@@ -158,9 +158,7 @@ private[sql] object BOOLEAN extends NativeColumnType(BooleanType, 4, 1) {
buffer.put(if (v) 1.toByte else 0.toByte) buffer.put(if (v) 1.toByte else 0.toByte)
} }
override def extract(buffer: ByteBuffer) = { override def extract(buffer: ByteBuffer) = buffer.get() == 1
if (buffer.get() == 1) true else false
}
override def setField(row: MutableRow, ordinal: Int, value: Boolean) { override def setField(row: MutableRow, ordinal: Int, value: Boolean) {
row.setBoolean(ordinal, value) row.setBoolean(ordinal, value)
......
...@@ -209,7 +209,7 @@ trait ClientBase extends Logging { ...@@ -209,7 +209,7 @@ trait ClientBase extends Logging {
if (! localPath.isEmpty()) { if (! localPath.isEmpty()) {
val localURI = new URI(localPath) val localURI = new URI(localPath)
if (!ClientBase.LOCAL_SCHEME.equals(localURI.getScheme())) { if (!ClientBase.LOCAL_SCHEME.equals(localURI.getScheme())) {
val setPermissions = if (destName.equals(ClientBase.APP_JAR)) true else false val setPermissions = destName.equals(ClientBase.APP_JAR)
val destPath = copyRemoteFile(dst, qualifyForLocal(localURI), replication, setPermissions) val destPath = copyRemoteFile(dst, qualifyForLocal(localURI), replication, setPermissions)
val destFs = FileSystem.get(destPath.toUri(), conf) val destFs = FileSystem.get(destPath.toUri(), conf)
distCacheMgr.addResource(destFs, conf, destPath, localResources, LocalResourceType.FILE, distCacheMgr.addResource(destFs, conf, destPath, localResources, LocalResourceType.FILE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment