本文整理汇总了Scala中org.apache.hadoop.io.Writable类的典型用法代码示例。如果您正苦于以下问题:Scala Writable类的具体用法?Scala Writable怎么用?Scala Writable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Writable类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: WritableSerializer
//设置package包名称以及导入依赖的类
package org.hammerlab.hadoop.kryo
import java.io.{ DataInputStream, DataOutputStream }
import com.esotericsoftware.kryo.io.{ Input, Output }
import com.esotericsoftware.kryo.{ Kryo, Serializer }
import org.apache.hadoop.io.Writable
class WritableSerializer[T <: Writable](ctorArgs: Any*) extends Serializer[T] {
override def read(kryo: Kryo, input: Input, clz: Class[T]): T = {
val t = clz.newInstance()
t.readFields(new DataInputStream(input))
t
}
override def write(kryo: Kryo, output: Output, t: T): Unit = {
t.write(new DataOutputStream(output))
}
}
开发者ID:hammerlab,项目名称:spark-util,代码行数:20,代码来源:WritableSerializer.scala
示例2: execute
//设置package包名称以及导入依赖的类
package com.groupon.dse.mezzanine
import com.groupon.dse.kafka.common.WrappedMessage
import com.groupon.dse.mezzanine.converter.WritableConverter
import com.groupon.dse.mezzanine.extractor.{TopicAndEvent, WrappedMessageExtractor}
import com.groupon.dse.mezzanine.outputformat.StagingFileOutputFormat
import com.groupon.dse.mezzanine.partitioner.Partitioner
import com.groupon.dse.mezzanine.util.HDFSWriter
import com.groupon.dse.spark.plugins.ReceiverPlugin
import org.apache.hadoop.io.Writable
import org.apache.spark.rdd.RDD
import scala.concurrent.duration.Duration
import scala.reflect.ClassTag
override def execute(messages: RDD[WrappedMessage]): Unit = {
val topics = messages.mapPartitions(partitionIterator => {
if (partitionIterator.nonEmpty) {
Iterator((partitionIterator.next().topic, null))
} else {
Iterator.empty
}
}).reduceByKeyLocally((x, y) => x).keys
val topicToStagingPath = topics.map(topic => topic -> partitioner.relativeStagingDirectory(topic)).toMap
val topicEventRDD = extractor.extract(messages)
val pathEventRDD = topicEventRDD.mapPartitions(partitionIterator => {
if (partitionIterator.nonEmpty) {
val firstTopicAndEvent = partitionIterator.next()
val stagingPath = topicToStagingPath.get(firstTopicAndEvent.topic).get
(Iterator(firstTopicAndEvent) ++ partitionIterator).map(topicAndEvent => {
(stagingPath, converter.convert(topicAndEvent))
})
} else {
Iterator.empty
}
}).cache()
HDFSWriter.multiWriteToHDFSwithRetry(
pathEventRDD,
partitioner.stagingRoot,
classOf[StagingFileOutputFormat[K, V]],
retryInterval
)
}
}
开发者ID:groupon,项目名称:mezzanine,代码行数:50,代码来源:MezzaninePlugin.scala
示例3: CompactorListener
//设置package包名称以及导入依赖的类
package com.groupon.dse.mezzanine.compactor
import com.groupon.dse.mezzanine.partitioner.Partitioner
import org.apache.hadoop.fs.FileSystem
import org.apache.hadoop.io.Writable
import org.apache.spark.SparkContext
import org.apache.spark.groupon.metrics.UserMetricsSystem
import org.apache.spark.streaming.scheduler.{StreamingListener, StreamingListenerBatchCompleted}
class CompactorListener[K <: Writable, V <: Writable](val sparkContext: SparkContext,
val fs: FileSystem,
val partitioner: Partitioner,
val compactor: Compactor[K, V]) extends StreamingListener {
override def onBatchCompleted(batchCompleted: StreamingListenerBatchCompleted): Unit = {
// Get the leaf directories where staging files are written to for the topics we consume
val stagingLeafDirs = partitioner.stagingLeafDirectories(fs).filter(path => {
path.getName.startsWith(Partitioner.KeyPrefix)
})
stagingLeafDirs.par.foreach(stagingPath => {
val key = partitioner.keyForStagingDirectory(stagingPath)
val filesToCompact = compactor.getFilesToCompact(stagingPath, batchCompleted.batchInfo.processingEndTime.get)
if (filesToCompact.nonEmpty) {
val outputPath = partitioner.outputDirectory(key)
UserMetricsSystem.timer(s"mezzanine.write.time.output.$key").time({
compactor.saveToOutputDir(filesToCompact, outputPath)
})
filesToCompact.foreach(fs.delete(_, false))
}
})
}
}
开发者ID:groupon,项目名称:mezzanine,代码行数:35,代码来源:CompactorListener.scala
注:本文中的org.apache.hadoop.io.Writable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论