Skip to content

Commit

Permalink
Fixing pyspark and spark-shell CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Aug 8, 2014
1 parent 9de6a42 commit e630d19
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
7 changes: 6 additions & 1 deletion bin/pyspark
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ if [[ -n "$SPARK_TESTING" ]]; then
exit
fi

source $FWDIR/bin/utils.sh

# If a python file is provided, directly run spark-submit.
if [[ "$1" =~ \.py$ ]]; then
echo -e "\nWARNING: Running python applications through ./bin/pyspark is deprecated as of Spark 1.0." 1>&2
echo -e "Use ./bin/spark-submit <python file>\n" 1>&2
exec $FWDIR/bin/spark-submit "$@"
primary=$1
shift
gatherSparkSubmitOpts $@
exec $FWDIR/bin/spark-submit ${SUBMISSION_OPTS[@]} $primary ${APPLICATION_OPTS[@]}
else
# Only use ipython if no command line arguments were provided [SPARK-1134]
if [[ "$IPYTHON" = "1" ]]; then
Expand Down
9 changes: 6 additions & 3 deletions bin/spark-shell
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
exit 0
fi

function main(){
source $FWDIR/bin/utils.sh
gatherSparkSubmitOpts $@

function main() {
if $cygwin; then
# Workaround for issue involving JLine and Cygwin
# (see http://sourceforge.net/p/jline/bugs/40/).
Expand All @@ -46,11 +49,11 @@ function main(){
# (see https://github.com/sbt/sbt/issues/562).
stty -icanon min 1 -echo > /dev/null 2>&1
export SPARK_SUBMIT_OPTS="$SPARK_SUBMIT_OPTS -Djline.terminal=unix"
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main spark-shell "$@"
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main ${SUBMISSION_OPTS[@]} spark-shell ${APPLICATION_OPTS[@]}
stty icanon echo > /dev/null 2>&1
else
export SPARK_SUBMIT_OPTS
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main spark-shell "$@"
$FWDIR/bin/spark-submit --class org.apache.spark.repl.Main ${SUBMISSION_OPTS[@]} spark-shell ${APPLICATION_OPTS[@]}
fi
}

Expand Down
56 changes: 56 additions & 0 deletions bin/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Gather all all spark-submit options into SUBMISSION_OPTS
function gatherSparkSubmitOpts() {
SUBMISSION_OPTS=()
APPLICATION_OPTS=()
while (($#)); do
case $1 in
--master | --deploy-mode | --class | --name | --jars | --py-files | --files)
;&

--conf | --properties-file | --driver-memory | --driver-java-options)
;&

--driver-library-path | --driver-class-path | --executor-memory | --driver-cores)
;&

--total-executor-cores | --executor-cores | --queue | --num-executors | --archives)
if [[ $# -lt 2 ]]; then
usage
exit 1;
fi
SUBMISSION_OPTS+=($1); shift
SUBMISSION_OPTS+=($1); shift
;;

--verbose | -v | --supervise)
SUBMISSION_OPTS+=($1); shift
;;

*)
APPLICATION_OPTS+=($1); shift
;;
esac
done

export SUBMISSION_OPTS
export APPLICATION_OPTS
}
2 changes: 1 addition & 1 deletion python/pyspark/java_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def launch_gateway():
submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS")
submit_args = submit_args if submit_args is not None else ""
submit_args = shlex.split(submit_args)
command = [os.path.join(SPARK_HOME, script), "pyspark-shell"] + submit_args
command = [os.path.join(SPARK_HOME, script)] + submit_args + ["pyspark-shell"]
if not on_windows:
# Don't send ctrl-c / SIGINT to the Java gateway:
def preexec_func():
Expand Down

0 comments on commit e630d19

Please sign in to comment.