Skip to content

Commit 1b5f0a5

Browse files
author
Davies Liu
committed
Merge branch 'master' of github.com:apache/spark into sql
Conflicts: python/pyspark/sql.py
2 parents 2b2b983 + dae2161 commit 1b5f0a5

File tree

6 files changed

+72
-15
lines changed

6 files changed

+72
-15
lines changed

build/sbt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,32 @@ loadConfigFile() {
125125
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
126126
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
127127

128+
exit_status=127
129+
saved_stty=""
130+
131+
restoreSttySettings() {
132+
stty $saved_stty
133+
saved_stty=""
134+
}
135+
136+
onExit() {
137+
if [[ "$saved_stty" != "" ]]; then
138+
restoreSttySettings
139+
fi
140+
exit $exit_status
141+
}
142+
143+
saveSttySettings() {
144+
saved_stty=$(stty -g 2>/dev/null)
145+
if [[ ! $? ]]; then
146+
saved_stty=""
147+
fi
148+
}
149+
150+
saveSttySettings
151+
trap onExit INT
152+
128153
run "$@"
154+
155+
exit_status=$?
156+
onExit

build/sbt-launch-lib.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ execRunner () {
8181
echo ""
8282
}
8383

84-
exec "$@"
84+
"$@"
8585
}
8686

8787
addJava () {

python/pyspark/sql/dataframe.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,18 @@ def addColumn(self, colName, col):
540540
"""
541541
return self.select('*', col.alias(colName))
542542

543+
def to_pandas(self):
544+
"""
545+
Collect all the rows and return a `pandas.DataFrame`.
546+
547+
>>> df.to_pandas() # doctest: +SKIP
548+
age name
549+
0 2 Alice
550+
1 5 Bob
551+
"""
552+
import pandas as pd
553+
return pd.DataFrame.from_records(self.collect(), columns=self.columns)
554+
543555

544556
# Having SchemaRDD for backward compatibility (for docs)
545557
class SchemaRDD(DataFrame):
@@ -807,6 +819,19 @@ def cast(self, dataType):
807819
jc = self._jc.cast(jdt)
808820
return Column(jc, self.sql_ctx)
809821

822+
def to_pandas(self):
823+
"""
824+
Return a pandas.Series from the column
825+
826+
>>> df.age.to_pandas() # doctest: +SKIP
827+
0 2
828+
1 5
829+
dtype: int64
830+
"""
831+
import pandas as pd
832+
data = [c for c, in self.collect()]
833+
return pd.Series(data)
834+
810835

811836
def _aggregate_func(name, doc=""):
812837
""" Create a function for aggregator by name"""

yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,11 @@ private[spark] class Client(
435435

436436
// Include driver-specific java options if we are launching a driver
437437
if (isClusterMode) {
438-
sparkConf.getOption("spark.driver.extraJavaOptions")
438+
val driverOpts = sparkConf.getOption("spark.driver.extraJavaOptions")
439439
.orElse(sys.env.get("SPARK_JAVA_OPTS"))
440-
.map(Utils.splitCommandString).getOrElse(Seq.empty)
441-
.foreach(opts => javaOpts += opts)
440+
driverOpts.foreach { opts =>
441+
javaOpts ++= Utils.splitCommandString(opts).map(YarnSparkHadoopUtil.escapeForShell)
442+
}
442443
val libraryPaths = Seq(sys.props.get("spark.driver.extraLibraryPath"),
443444
sys.props.get("spark.driver.libraryPath")).flatten
444445
if (libraryPaths.nonEmpty) {
@@ -460,7 +461,7 @@ private[spark] class Client(
460461
val msg = s"$amOptsKey is not allowed to alter memory settings (was '$opts')."
461462
throw new SparkException(msg)
462463
}
463-
javaOpts ++= Utils.splitCommandString(opts)
464+
javaOpts ++= Utils.splitCommandString(opts).map(YarnSparkHadoopUtil.escapeForShell)
464465
}
465466
}
466467

yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@ class ExecutorRunnable(
128128

129129
// Set the JVM memory
130130
val executorMemoryString = executorMemory + "m"
131-
javaOpts += "-Xms" + executorMemoryString + " -Xmx" + executorMemoryString + " "
131+
javaOpts += "-Xms" + executorMemoryString
132+
javaOpts += "-Xmx" + executorMemoryString
132133

133134
// Set extra Java options for the executor, if defined
134135
sys.props.get("spark.executor.extraJavaOptions").foreach { opts =>
135-
javaOpts += opts
136+
javaOpts ++= Utils.splitCommandString(opts).map(YarnSparkHadoopUtil.escapeForShell)
136137
}
137138
sys.env.get("SPARK_JAVA_OPTS").foreach { opts =>
138-
javaOpts += opts
139+
javaOpts ++= Utils.splitCommandString(opts).map(YarnSparkHadoopUtil.escapeForShell)
139140
}
140141
sys.props.get("spark.executor.extraLibraryPath").foreach { p =>
141142
prefixEnv = Some(Utils.libraryPathEnvPrefix(Seq(p)))
@@ -173,11 +174,11 @@ class ExecutorRunnable(
173174
// The options are based on
174175
// http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html#0.0.0.%20When%20to%20Use
175176
// %20the%20Concurrent%20Low%20Pause%20Collector|outline
176-
javaOpts += " -XX:+UseConcMarkSweepGC "
177-
javaOpts += " -XX:+CMSIncrementalMode "
178-
javaOpts += " -XX:+CMSIncrementalPacing "
179-
javaOpts += " -XX:CMSIncrementalDutyCycleMin=0 "
180-
javaOpts += " -XX:CMSIncrementalDutyCycle=10 "
177+
javaOpts += "-XX:+UseConcMarkSweepGC"
178+
javaOpts += "-XX:+CMSIncrementalMode"
179+
javaOpts += "-XX:+CMSIncrementalPacing"
180+
javaOpts += "-XX:CMSIncrementalDutyCycleMin=0"
181+
javaOpts += "-XX:CMSIncrementalDutyCycle=10"
181182
}
182183
*/
183184

yarn/src/test/scala/org/apache/spark/deploy/yarn/YarnClusterSuite.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class YarnClusterSuite extends FunSuite with BeforeAndAfterAll with Matchers wit
7575
private var oldConf: Map[String, String] = _
7676

7777
override def beforeAll() {
78+
super.beforeAll()
79+
7880
tempDir = Utils.createTempDir()
7981

8082
val logConfDir = new File(tempDir, "log4j")
@@ -129,8 +131,8 @@ class YarnClusterSuite extends FunSuite with BeforeAndAfterAll with Matchers wit
129131
sys.props += ("spark.executor.instances" -> "1")
130132
sys.props += ("spark.driver.extraClassPath" -> childClasspath)
131133
sys.props += ("spark.executor.extraClassPath" -> childClasspath)
132-
133-
super.beforeAll()
134+
sys.props += ("spark.executor.extraJavaOptions" -> "-Dfoo=\"one two three\"")
135+
sys.props += ("spark.driver.extraJavaOptions" -> "-Dfoo=\"one two three\"")
134136
}
135137

136138
override def afterAll() {

0 commit comments

Comments
 (0)