首页 技术 正文
技术 2022年11月21日
0 收藏 635 点赞 4,827 浏览 1406 个字

1、创建scala maven项目
选择骨架的时候为org.scala-tools.archetypes:scala-aechetype-simple 1.2
2、导入包,进入spark官网Documentation选择第二个-选择自己的spark版本-选择programming guides-选择第二个-查看spark版本对应的依赖的版本
将pom中的内容为:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>bigdata</artifactId>
<groupId>com.laotou</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spark_day01_01</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
</project>
代码:
object HelloSpark {
def main(args: Array[String]): Unit = {
//spark主要是做计算 ---> 最终是不是要打包发布到spark集群中 因为集群中要运行多个spark程序,所以事先要给job取个名字
val conf = new SparkConf().setAppName("sparkTest").setMaster("local[2]")
val sc = new SparkContext(conf)
sc.textFile("D://helloSpark.txt").flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).foreach(println(_))
}
}

3、如果采用的scala版本与spark要求的版本不一致时,会报错NoSunchMethodError

解决:
修改scala的版本。采用绿色版。(这里是将scala-sdk-2.10.6的压缩包)解压–>手动配置一下。
进去spark官网查看当前操作的spark版本对应的依赖scala版本
Spark runs on Java 7+, Python 2.6+ and R 3.1+. For the Scala API, Spark 1.6.3 uses Scala 2.10. You will need to use a compatible Scala version (2.10.x).
idea选择file-project structure-选择需要处理的项目-选择spark版本对应的dependencies-右边有个+号添加需要的依赖scala版本:scala-sdk-2.10.6

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893