Skip to content

Commit e630d19

Browse files
committed
Fixing pyspark and spark-shell CLI options
1 parent 9de6a42 commit e630d19

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

bin/pyspark

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,16 @@ if [[ -n "$SPARK_TESTING" ]]; then
8686
exit
8787
fi
8888

89+
source $FWDIR/bin/utils.sh
90+
8991
# If a python file is provided, directly run spark-submit.
9092
if [[ "$1" =~ \.py$ ]]; then
9193
echo -e "\nWARNING: Running python applications through ./bin/pyspark is deprecated as of Spark 1.0." 1>&2
9294
echo -e "Use ./bin/spark-submit <python file>\n" 1>&2
93-
exec $FWDIR/bin/spark-submit "$@"
95+
primary=$1
96+
shift
97+
gatherSparkSubmitOpts $@
98+
exec $FWDIR/bin/spark-submit ${SUBMISSION_OPTS[@]} $primary ${APPLICATION_OPTS[@]}
9499
else
95100
# Only use ipython if no command line arguments were provided [SPARK-1134]
96101
if [[ "$IPYTHON" = "1" ]]; then

bin/spark-shell

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
3737
exit 0
3838
fi
3939

40-
function main(){
40+
source $FWDIR/bin/utils.sh
41+
gatherSparkSubmitOpts $@
42+
43+
function main() {
4144
if $cygwin; then
4245
# Workaround for issue involving JLine and Cygwin
4346
# (see http://sourceforge.net/p/jline/bugs/40/).
@@ -46,11 +49,11 @@ function main(){
4649
# (see https://github.com/sbt/sbt/issues/562).
4750
stty -icanon min 1 -echo > /dev/null 2>&1
4851
export SPARK_SUBMIT_OPTS="$SPARK_SUBMIT_OPTS -Djline.terminal=unix"
49-
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main spark-shell "$@"
52+
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main ${SUBMISSION_OPTS[@]} spark-shell ${APPLICATION_OPTS[@]}
5053
stty icanon echo > /dev/null 2>&1
5154
else
5255
export SPARK_SUBMIT_OPTS
53-
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main spark-shell "$@"
56+
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main ${SUBMISSION_OPTS[@]} spark-shell ${APPLICATION_OPTS[@]}
5457
fi
5558
}
5659

bin/utils.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# Gather all all spark-submit options into SUBMISSION_OPTS
21+
function gatherSparkSubmitOpts() {
22+
SUBMISSION_OPTS=()
23+
APPLICATION_OPTS=()
24+
while (($#)); do
25+
case $1 in
26+
--master | --deploy-mode | --class | --name | --jars | --py-files | --files)
27+
;&
28+
29+
--conf | --properties-file | --driver-memory | --driver-java-options)
30+
;&
31+
32+
--driver-library-path | --driver-class-path | --executor-memory | --driver-cores)
33+
;&
34+
35+
--total-executor-cores | --executor-cores | --queue | --num-executors | --archives)
36+
if [[ $# -lt 2 ]]; then
37+
usage
38+
exit 1;
39+
fi
40+
SUBMISSION_OPTS+=($1); shift
41+
SUBMISSION_OPTS+=($1); shift
42+
;;
43+
44+
--verbose | -v | --supervise)
45+
SUBMISSION_OPTS+=($1); shift
46+
;;
47+
48+
*)
49+
APPLICATION_OPTS+=($1); shift
50+
;;
51+
esac
52+
done
53+
54+
export SUBMISSION_OPTS
55+
export APPLICATION_OPTS
56+
}

python/pyspark/java_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def launch_gateway():
3939
submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS")
4040
submit_args = submit_args if submit_args is not None else ""
4141
submit_args = shlex.split(submit_args)
42-
command = [os.path.join(SPARK_HOME, script), "pyspark-shell"] + submit_args
42+
command = [os.path.join(SPARK_HOME, script)] + submit_args + ["pyspark-shell"]
4343
if not on_windows:
4444
# Don't send ctrl-c / SIGINT to the Java gateway:
4545
def preexec_func():

0 commit comments

Comments
 (0)