@@ -76,53 +76,86 @@ private[sql] case class ExecutedCommand(cmd: RunnableCommand) extends SparkPlan
7676 */
7777@ DeveloperApi
7878case class SetCommand (
79- kv : Option [(String , Option [String ])],
80- override val output : Seq [Attribute ])
79+ kv : Option [(String , Option [String ])])
8180 extends RunnableCommand with Logging {
8281
83- override def run (sqlContext : SQLContext ): Seq [Row ] = kv match {
82+ private def keyValueOutput : Seq [Attribute ] = {
83+ val schema = StructType (
84+ StructField (" key" , StringType , false ) ::
85+ StructField (" value" , StringType , false ) :: Nil )
86+ schema.toAttributes
87+ }
88+
89+ private val (_output, runFunc): (Seq [Attribute ], SQLContext => Seq [Row ]) = kv match {
8490 // Configures the deprecated "mapred.reduce.tasks" property.
8591 case Some ((SQLConf .Deprecated .MAPRED_REDUCE_TASKS , Some (value))) =>
86- logWarning(
87- s " Property ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } is deprecated, " +
88- s " automatically converted to ${SQLConf .SHUFFLE_PARTITIONS .key} instead. " )
89- if (value.toInt < 1 ) {
90- val msg = s " Setting negative ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } for automatically " +
91- " determining the number of reducers is not supported."
92- throw new IllegalArgumentException (msg)
93- } else {
94- sqlContext.setConf(SQLConf .SHUFFLE_PARTITIONS .key, value)
95- Seq (Row (s " ${SQLConf .SHUFFLE_PARTITIONS .key}= $value" ))
92+ val runFunc = (sqlContext : SQLContext ) => {
93+ logWarning(
94+ s " Property ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } is deprecated, " +
95+ s " automatically converted to ${SQLConf .SHUFFLE_PARTITIONS .key} instead. " )
96+ if (value.toInt < 1 ) {
97+ val msg = s " Setting negative ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } for automatically " +
98+ " determining the number of reducers is not supported."
99+ throw new IllegalArgumentException (msg)
100+ } else {
101+ sqlContext.setConf(SQLConf .SHUFFLE_PARTITIONS .key, value)
102+ Seq (Row (SQLConf .SHUFFLE_PARTITIONS .key, value))
103+ }
96104 }
105+ (keyValueOutput, runFunc)
97106
98107 // Configures a single property.
99108 case Some ((key, Some (value))) =>
100- sqlContext.setConf(key, value)
101- Seq (Row (s " $key= $value" ))
109+ val runFunc = (sqlContext : SQLContext ) => {
110+ sqlContext.setConf(key, value)
111+ Seq (Row (key, value))
112+ }
113+ (keyValueOutput, runFunc)
102114
103115 // (In Hive, "SET" returns all changed properties while "SET -v" returns all properties.)
104116 // Queries all key-value pairs that are set in the SQLConf of the sqlContext.
105117 case None =>
106- sqlContext.getAllConfs.map { case (k, v) => Row (s " $k= $v" ) }.toSeq
118+ val runFunc = (sqlContext : SQLContext ) => {
119+ sqlContext.getAllConfs.map { case (k, v) => Row (k, v) }.toSeq
120+ }
121+ (keyValueOutput, runFunc)
107122
108123 // Queries all properties along with their default values and docs that are defined in the
109124 // SQLConf of the sqlContext.
110125 case Some ((" -v" , None )) =>
111- sqlContext.conf.getAllDefinedConfs.map { case (key, defaultValue, doc) =>
112- Row (s " $key\t default: $defaultValue\t $doc" )
126+ val runFunc = (sqlContext : SQLContext ) => {
127+ sqlContext.conf.getAllDefinedConfs.map { case (key, defaultValue, doc) =>
128+ Row (key, defaultValue, doc)
129+ }
113130 }
131+ val schema = StructType (
132+ StructField (" key" , StringType , false ) ::
133+ StructField (" default" , StringType , false ) ::
134+ StructField (" meaning" , StringType , false ) :: Nil )
135+ (schema.toAttributes, runFunc)
114136
115137 // Queries the deprecated "mapred.reduce.tasks" property.
116138 case Some ((SQLConf .Deprecated .MAPRED_REDUCE_TASKS , None )) =>
117- logWarning(
118- s " Property ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } is deprecated, " +
119- s " showing ${SQLConf .SHUFFLE_PARTITIONS .key} instead. " )
120- Seq (Row (s " ${SQLConf .SHUFFLE_PARTITIONS .key}= ${sqlContext.conf.numShufflePartitions}" ))
139+ val runFunc = (sqlContext : SQLContext ) => {
140+ logWarning(
141+ s " Property ${SQLConf .Deprecated .MAPRED_REDUCE_TASKS } is deprecated, " +
142+ s " showing ${SQLConf .SHUFFLE_PARTITIONS .key} instead. " )
143+ Seq (Row (SQLConf .SHUFFLE_PARTITIONS .key, sqlContext.conf.numShufflePartitions.toString))
144+ }
145+ (keyValueOutput, runFunc)
121146
122147 // Queries a single property.
123148 case Some ((key, None )) =>
124- Seq (Row (s " $key= ${sqlContext.getConf(key, " <undefined>" )}" ))
149+ val runFunc = (sqlContext : SQLContext ) => {
150+ Seq (Row (key, sqlContext.getConf(key, " <undefined>" )))
151+ }
152+ (keyValueOutput, runFunc)
125153 }
154+
155+ override val output : Seq [Attribute ] = _output
156+
157+ override def run (sqlContext : SQLContext ): Seq [Row ] = runFunc(sqlContext)
158+
126159}
127160
128161/**
0 commit comments