Skip to content

Commit be4736b

Browse files
committed
Report better error message when running JDBC/CLI without hive-thriftserver profile enabled
1 parent e0f9462 commit be4736b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

bin/spark-sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
set -o posix
2525

2626
CLASS="org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver"
27+
CLASS_NOT_FOUND_EXIT_STATUS=1
2728

2829
# Figure out where Spark is installed
2930
FWDIR="$(cd `dirname $0`/..; pwd)"
@@ -91,4 +92,13 @@ while (($#)); do
9192
esac
9293
done
9394

94-
exec "$FWDIR"/bin/spark-submit --class $CLASS "${SUBMISSION_ARGS[@]}" spark-internal "${CLI_ARGS[@]}"
95+
eval "$FWDIR"/bin/spark-submit --class $CLASS ${SUBMISSION_ARGS[*]} spark-internal ${CLI_ARGS[*]}
96+
exit_status=$?
97+
98+
if [[ exit_status -eq CLASS_NOT_FOUND_EXIT_STATUS ]]; then
99+
echo
100+
echo "Failed to load Spark SQL CLI main class $CLASS."
101+
echo "You need to build Spark with -Phive."
102+
fi
103+
104+
exit $exit_status

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ object SparkSubmit {
5454
private val SPARK_SHELL = "spark-shell"
5555
private val PYSPARK_SHELL = "pyspark-shell"
5656

57+
private val CLASS_NOT_FOUND_EXIT_STATUS = 1
58+
5759
// Exposed for testing
5860
private[spark] var exitFn: () => Unit = () => System.exit(-1)
5961
private[spark] var printStream: PrintStream = System.err
@@ -311,8 +313,18 @@ object SparkSubmit {
311313
System.setProperty(key, value)
312314
}
313315

314-
val mainClass = Class.forName(childMainClass, true, loader)
316+
var mainClass: Class[_] = null
317+
318+
try {
319+
mainClass = Class.forName(childMainClass, true, loader)
320+
} catch {
321+
case e: ClassNotFoundException =>
322+
e.printStackTrace(printStream)
323+
System.exit(CLASS_NOT_FOUND_EXIT_STATUS)
324+
}
325+
315326
val mainMethod = mainClass.getMethod("main", new Array[String](0).getClass)
327+
316328
try {
317329
mainMethod.invoke(null, childArgs.toArray)
318330
} catch {

sbin/start-thriftserver.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set -o posix
2727
FWDIR="$(cd `dirname $0`/..; pwd)"
2828

2929
CLASS="org.apache.spark.sql.hive.thriftserver.HiveThriftServer2"
30+
CLASS_NOT_FOUND_EXIT_STATUS=1
3031

3132
function usage {
3233
echo "Usage: ./sbin/start-thriftserver [options] [thrift server options]"
@@ -75,4 +76,13 @@ while (($#)); do
7576
esac
7677
done
7778

78-
exec "$FWDIR"/bin/spark-submit --class $CLASS "${SUBMISSION_ARGS[@]}" spark-internal "${THRIFT_SERVER_ARGS[@]}"
79+
eval "$FWDIR"/bin/spark-submit --class $CLASS ${SUBMISSION_ARGS[*]} spark-internal ${THRIFT_SERVER_ARGS[*]}
80+
exit_status=$?
81+
82+
if [[ exit_status -eq CLASS_NOT_FOUND_EXIT_STATUS ]]; then
83+
echo
84+
echo "Failed to load Hive Thrift server main class $CLASS."
85+
echo "You need to build Spark with -Phive."
86+
fi
87+
88+
exit $exit_status

0 commit comments

Comments
 (0)