Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
improve SET / SET -v command
  • Loading branch information
bomeng committed Apr 21, 2016
commit 01d3e5a545eeced71b82d26a8407ea5e1d8f49ab
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import org.apache.spark.sql.execution.debug._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._

import scala.collection.immutable.ListMap

/**
* A logical command that is executed for its side-effects. `RunnableCommand`s are
* wrapped in `ExecutedCommand` during execution.
Expand Down Expand Up @@ -181,17 +183,18 @@ case class SetCommand(kv: Option[(String, Option[String])]) extends RunnableComm
// Queries all key-value pairs that are set in the SQLConf of the sqlContext.
case None =>
val runFunc = (sqlContext: SQLContext) => {
sqlContext.getAllConfs.map { case (k, v) => Row(k, v) }.toSeq
sqlContext.getAllConfs.toSeq.sortBy(_._1).map { case (k, v) => Row(k, v) } ++
getEnvList(withDoc = false)
}
(keyValueOutput, runFunc)

// Queries all properties along with their default values and docs that are defined in the
// SQLConf of the sqlContext.
case Some(("-v", None)) =>
val runFunc = (sqlContext: SQLContext) => {
sqlContext.conf.getAllDefinedConfs.map { case (key, defaultValue, doc) =>
sqlContext.conf.getAllDefinedConfs.sortBy(_._1).map { case (key, defaultValue, doc) =>
Row(key, defaultValue, doc)
}
} ++ getEnvList(withDoc = true)
}
val schema = StructType(
StructField("key", StringType, false) ::
Expand Down Expand Up @@ -225,6 +228,20 @@ case class SetCommand(kv: Option[(String, Option[String])]) extends RunnableComm

override def run(sqlContext: SQLContext): Seq[Row] = runFunc(sqlContext)

/**
* get the system environment properties as a sequence
* @param withDoc whether the result has a doc column or not
* @return the sequence of the rows containing the key/value pair of system properties
*/
private def getEnvList(withDoc: Boolean) = {
import scala.collection.JavaConverters._
System.getenv().asScala.toSeq.sortBy(_._1).map {
case (k, v) => if (withDoc) Row(s"env:$k", v, "") else Row(s"env:$k", v)
} ++
System.getProperties.asScala.toSeq.sortBy(_._1).map {
case (k, v) => if (withDoc) Row(s"system:$k", v, "") else Row(s"system:$k", v)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
}

test("set / set -v") {
checkExistence(sql("set"), true, "env:", "system:")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a test case that checks the value of SPARK_TESTING?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SPARK_TESTING is not in sys.env nor sys.props while running the test cases. Any suggestions to add the test cases for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found out that current test cases SQLQuerySuite and HiveQuerySuite have intensive test coverage for SET command.

checkExistence(sql("set -v"), true, "env:", "system:")
}
}