我已经在我自己的 ubuntu linux18.04 机器上安装并配置了 jdk 1.8/hadoop 2.8.4/scala 2.10.6,WordCount java 应用程序使用“hadoop jar”命令运行正常。
然后我在与 java wordcount 相同的 intellij 项目中尝试了 scala 代码,代码如下:
import java.io.IOException
import java.util._
import org.apache.hadoop.fs.Path
import org.apache.hadoop.io._
import org.apache.hadoop.mapred._
object wc01 {
@throws[Exception]
def main(args: Array[String]) {
val conf: JobConf = new JobConf(this.getClass)
conf.setJobName("WordCountScala")
conf.setOutputKeyClass(classOf[Text])
conf.setOutputValueClass(classOf[IntWritable])
conf.setMapperClass(classOf[Map])
conf.setCombinerClass(classOf[Reduce])
conf.setReducerClass(classOf[Reduce])
conf.setInputFormat(classOf[TextInputFormat])
conf.setOutputFormat(classOf[TextOutputFormat[Text, IntWritable]])
FileInputFormat.setInputPaths(conf, new Path(args(0)))
FileOutputFormat.setOutputPath(conf, new Path(args(1)))
JobClient.runJob(conf)
}
class Map extends MapReduceBase with Mapper[LongWritable, Text, Text, IntWritable] {
private final val one = new IntWritable(1)
private val word = new Text()
@throws[IOException]
def map(key: LongWritable, value: Text, output: OutputCollector[Text, IntWritable], reporter: Reporter) {
val line: String = value.toString
line.split(" ").foreach { token =>
word.set(token)
output.collect(word, one)
}
}
}
class Reduce extends MapReduceBase with Reducer[Text, IntWritable, Text, IntWritable] {
@throws[IOException]
def reduce(key: Text, values: Iterator[IntWritable], output: OutputCollector[Text, IntWritable], reporter: Reporter) {
import scala.collection.JavaConversions._
val sum = values.toList.reduce((valueOne, valueTwo) => new IntWritable(valueOne.get() + valueTwo.get()))
output.collect(key, new IntWritable(sum.get()))
}
}
}
我编译打包,用hadoop jar运行,报错:
hdfs@ubuntu:$ hadoop jar my_java_scala_mr-1.0-SNAPSHOT.jar wc01 my-input my-output
18/08/26 01:30:58 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
18/08/26 01:30:58 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
18/08/26 01:30:58 WARN mapreduce.JobResourceUploader: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
18/08/26 01:30:58 INFO mapred.FileInputFormat: Total input files to process : 1
18/08/26 01:30:58 INFO mapreduce.JobSubmitter: number of splits:2
18/08/26 01:30:58 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1535165327468_0012
18/08/26 01:30:59 INFO impl.YarnClientImpl: Submitted application application_1535165327468_0012
18/08/26 01:30:59 INFO mapreduce.Job: The url to track the job: http://ubuntu:8088/proxy/application_1535165327468_0012/
18/08/26 01:30:59 INFO mapreduce.Job: Running job: job_1535165327468_0012
18/08/26 01:31:04 INFO mapreduce.Job: Job job_1535165327468_0012 running in uber mode : false
18/08/26 01:31:04 INFO mapreduce.Job: map 0% reduce 0%
18/08/26 01:31:08 INFO mapreduce.Job: Task Id : attempt_1535165327468_0012_m_000000_0, Status : FAILED
Error: java.lang.ClassNotFoundException: scala.Function2
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
我想知道我是否需要任何额外的 hadoop java 包来支持 scala MR?我没有在我的 pom.xml 中指定任何自定义包语句,我只是“mvn package”来生成我的 jar,看起来没问题。
我该如何解决这个问题?
最佳答案
听起来您缺少 Scala 标准库。尝试将 org.scala-lang/scala-library/2.12.6 添加到您的依赖项中。
关于java - scala mapreduce 异常 : java. lang.ClassNotFoundException : scala. Function2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52024576/
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我早就知道Ruby中的“常量”(即大写的变量名)不是真正常量。与其他编程语言一样,对对象的引用是唯一存储在变量/常量中的东西。(侧边栏:Ruby确实具有“卡住”引用对象不被修改的功能,据我所知,许多其他语言都没有提供这种功能。)所以这是我的问题:当您将一个值重新分配给常量时,您会收到如下警告:>>FOO='bar'=>"bar">>FOO='baz'(irb):2:warning:alreadyinitializedconstantFOO=>"baz"有没有办法强制Ruby抛出异常而不是打印警告?很难弄清楚为什么有时会发生重新分配。 最佳答案
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我有一个涉及多台机器、消息队列和事务的问题。因此,例如用户点击网页,点击将消息发送到另一台机器,该机器将付款添加到用户的帐户。每秒可能有数千次点击。事务的所有方面都应该是容错的。我以前从未遇到过这样的事情,但一些阅读表明这是一个众所周知的问题。所以我的问题。我假设安全的方法是使用两阶段提交,但协议(protocol)是阻塞的,所以我不会获得所需的性能,我是否正确?我通常写Ruby,但似乎Redis之类的数据库和Rescue、RabbitMQ等消息队列系统对我的帮助不大——即使我实现某种两阶段提交,如果Redis崩溃,数据也会丢失,因为它本质上只是内存。所有这些让我开始关注erlang和
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候