温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用scala编写wordcount程序

发布时间:2021-12-09 09:20:18 来源:亿速云 阅读:169 作者:iii 栏目:开发技术

本篇内容介绍了“如何使用scala编写wordcount程序”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

直接上程序吧
一、公共类

  1. <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">

  2.   <modelVersion>4.0.0</modelVersion>

  3.   <groupId>testScala</groupId>

  4.   <artifactId>testScala</artifactId>

  5.   <version>1.0</version>

  6.   <inceptionYear>2008</inceptionYear>

  7.   <properties>

  8.     <scala.version>2.11.8</scala.version>

  9.     <hadoop.version>2.6.0-cdh6.7.0</hadoop.version>

  10.     <spark.version>2.2.1</spark.version>

  11.     <mysql.version>5.1.25</mysql.version>

  12.   </properties>


  13.   <repositories>

  14.     <repository>

  15.       <id>scala-tools.org</id>

  16.       <name>Scala-Tools Maven2 Repository</name>

  17.       <url>http://scala-tools.org/repo-releases</url>

  18.     </repository>


  19.     <repository>

  20.       <id>cloudera</id>

  21.       <name>cloudera</name>

  22.       <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>

  23.     </repository>

  24.   </repositories>


  25.   <pluginRepositories>

  26.     <pluginRepository>

  27.       <id>scala-tools.org</id>

  28.       <name>Scala-Tools Maven2 Repository</name>

  29.       <url>http://scala-tools.org/repo-releases</url>

  30.     </pluginRepository>

  31.   </pluginRepositories>


  32.   <dependencies>

  33.     <dependency>

  34.       <groupId>org.apache.spark</groupId>

  35.       <artifactId>spark-core_2.11</artifactId>

  36.       <version>${spark.version}</version>

  37.     </dependency>

  38.     <dependency>

  39.       <groupId>org.scala-lang</groupId>

  40.       <artifactId>scala-library</artifactId>

  41.       <version>${scala.version}</version>

  42.     </dependency>

  43.     <dependency>

  44.       <groupId>junit</groupId>

  45.       <artifactId>junit</artifactId>

  46.       <version>4.4</version>

  47.       <scope>test</scope>

  48.     </dependency>

  49.     <dependency>

  50.       <groupId>org.specs</groupId>

  51.       <artifactId>specs</artifactId>

  52.       <version>1.2.5</version>

  53.       <scope>test</scope>

  54.     </dependency>


  55.     <dependency>

  56.       <groupId>org.apache.hadoop</groupId>

  57.       <artifactId>hadoop-client</artifactId>

  58.       <version>${hadoop.version}</version>

  59.     </dependency>


  60.     <dependency>

  61.       <groupId>mysql</groupId>

  62.       <artifactId>mysql-connector-java</artifactId>

  63.       <version>${mysql.version}</version>

  64.     </dependency>

  65.   </dependencies>


  66.   <build>

  67.     <sourceDirectory>src/main/scala</sourceDirectory>

  68.     <testSourceDirectory>src/test/scala</testSourceDirectory>

  69.     <plugins>

  70.       <plugin>

  71.         <groupId>org.scala-tools</groupId>

  72.         <artifactId>maven-scala-plugin</artifactId>

  73.         <executions>

  74.           <execution>

  75.             <goals>

  76.               <goal>compile</goal>

  77.               <goal>testCompile</goal>

  78.             </goals>

  79.           </execution>

  80.         </executions>

  81.         <configuration>

  82.           <scalaVersion>${scala.version}</scalaVersion>

  83.           <args>

  84.             <arg>-target:jvm-1.5</arg>

  85.           </args>

  86.         </configuration>

  87.       </plugin>

  88.       <plugin>

  89.         <groupId>org.apache.maven.plugins</groupId>

  90.         <artifactId>maven-eclipse-plugin</artifactId>

  91.         <configuration>

  92.           <downloadSources>true</downloadSources>

  93.           <buildcommands>

  94.             <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>

  95.           </buildcommands>

  96.           <additionalProjectnatures>

  97.             <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>

  98.           </additionalProjectnatures>

  99.           <classpathContainers>

  100.             <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>

  101.             <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>

  102.           </classpathContainers>

  103.         </configuration>

  104.       </plugin>

  105.     </plugins>

  106.   </build>

  107.   <reporting>

  108.     <plugins>

  109.       <plugin>

  110.         <groupId>org.scala-tools</groupId>

  111.         <artifactId>maven-scala-plugin</artifactId>

  112.         <configuration>

  113.           <scalaVersion>${scala.version}</scalaVersion>

  114.         </configuration>

  115.       </plugin>

  116.     </plugins>

  117.   </reporting>

  118. </project>

六、测试数据
hdfs dfs -ls /ruozedata/scala
Found 3 items
-rw-r--r--   3 hadoop supergroup         24 2018-02-12 14:48 /ruozedata/scala/201802121449-1.txt
-rw-r--r--   3 hadoop supergroup         12 2018-02-12 14:48 /ruozedata/scala/201802121449-2.txt
-rw-r--r--   3 hadoop supergroup         12 2018-02-12 14:48 /ruozedata/scala/201802121449-3.txt
-----------------------------------------------------------------------------------------------------------
hdfs dfs -cat /ruozedata/scala/201802121449-1.txt
hello   world
hello   worls

hdfs dfs -cat /ruozedata/scala/201802121449-2.txt
hello   ruoze

hdfs dfs -cat /ruozedata/scala/201802121449-3.txt
ruoze   hello

七、测试结果
如何使用scala编写wordcount程序

“如何使用scala编写wordcount程序”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI