马上注册,结交更多数据大咖,获取更多知识干货,轻松玩转大数据
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
程序代码如下:
[Scala] 纯文本查看 复制代码 import org.apache.spark.{SparkContext, SparkConf}
/**
* Created by agile on 2015/9/21.
*/
object sqlTest
{
def main(args: Array[String])
{
val conf = new SparkConf().setAppName("sqlTest")
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.implicits._
import org.apache.spark.sql._
val df1 = sc.makeRDD(6 to 10).map(i => (i, i * 3)).toDF("single", "triple")
df1.registerTempTable("t1")
sqlContext.udf.register("calcC1",(t:Int)=>{t*0.2})
val df2 = sqlContext.sql("select single,triple,calcC1(single) C1 from t1")
df2.collect().foreach(x=>println(x))
sc.stop()
}
}
在spark-shell下正常运行。
编译之后使用
bin/spark-submit --master spark://127.0.0.1:7077 --class sqlTest kunlun.ces.sequoiadb.jar
就运行不下去了,错误如下
[AppleScript] 纯文本查看 复制代码 15/09/21 04:26:47 INFO SparkDeploySchedulerBackend: SchedulerBackend is ready for scheduling beginning after reached minRegisteredResourcesRatio: 0.0
Exception in thread "main" java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaUniverse$JavaMirror;
at sqlTest$.main(sqlTest.scala:18)
at sqlTest.main(sqlTest.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:569)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:166)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:189)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:110)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
求各位大师解答。
|