1. 程式人生 > >cdh5支援spark-sql cli怪招

cdh5支援spark-sql cli怪招

CDH5.7.0預設情況下是沒有提供spark-sql cli的,我曾嘗試用tarball以standalone模式部署過spark叢集,都是自帶spark-sql命令,於是就想到Copy Tarball裡的spark-sql檔案到$SPARK_HOME/bin目錄下

cp ./bin/spark-sql /opt/cloudera/parcels/CDH/lib/spark/bin/

執行./spark-sql,可悲的是報錯

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 java.lang.ClassNotFoundException
:org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(NativeMethod) at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(NativeMethod) at java.lang.Class.forName(Class.java:270) at org.apache.spark.util.Utils$.classForName(Utils.scala:175) at org.apache.spark.deploy.SparkSubmit
$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:689) at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181) at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206) at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121) at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) Failed toload main classorg.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver. You need tobuild Spark with-Phive and-Phive-thriftserver.

異常提示已經很明顯,在網上查了很多資料,千篇一律是要加入hive&hivethriftserver重新編譯原始碼才能支援,對我等不是搞基礎架構只要能熟練用好spark的人來說,還沒編譯原始碼的習慣,自動就過濾該方法了。

既然是org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver 類找不到,那就Copy Tarball到底,將與之相關的jar也同樣拷貝過來,其實就是spark-assembly-1.6.1-hadoop2.6.0.jar(我下載的是官網spark1.6.1 on hadoop2.6),接著修改spark-sql指令碼,將依賴的jar加入進來

export _SPARK_CMD_USAGE=”Usage: ./bin/spark-sql [options] [cli option]”
exec “${SPARK_HOME}”/bin/spark-submit –jars /opt/cloudera/parcels/CDH/lib/spark/spark-assembly-1.6.1-hadoop2.6.0.jar –class org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver “[email protected]

標紅的–jars部分是額外增加的

再執行./spark-sql,  命令列啟動起來了,緊接著執行了show tables;   select * from table* ,都沒任何問題,大功告成!

嚴重說明:本人裝的是CDH5.7.0整合的是SPARK1.6.0,Tarball是下載的SPARK1.6.1 on hadoop2.6,其他舊的版本沒有測試過。