• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Writable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala LogisticRegressionWithLBFGS类代码示例发布时间:2022-05-23
下一篇:
Scala Duration类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap