Using Partitioner in Spark

Source: Internet
Author: User

import org.apache.spark._import sparkcontext._import org.apache.spark.sparkconfimport  java.util.dateimport java.text.simpledateformatimport org.apache.hadoop.io.textimport  org.apache.hadoop.mapred.textoutputformatimport org.apache.spark.partitionerobject partitioner  {   def main (args: array[string]): unit = {         val time = new simpledateformat ("MMddHHmm"). Format (New Date () );     val sparkconf =  new sparkconf (). SetAppName ("Wordcount_" + Time)         sparkconf.set ("Mapreduce.framework.name",  "yarn");     val sc =new sparkcontext (sparkconf)          val textfile = sc.textfile (         "hdfs:// Namenode:9000/data/mapreduce/cHuping/test_in_1/new5 ",  1). Cache ()         val result =  textFile.flatMap  (Line => line.split ("T")  ) .    map  ( word =>  (word,1)). Reducebykey (new testpartitioner, _+_)          result.saveastextfile ("Hdfs://namenode:9000/data/zk/test/partitioner" +time)      sc.stop ()   }}class testPartitioner extends Partitioner{           val numPartitions = 3              def getpartition (Key: any) =1    Specify to the first few reduce}

The program here is only a test program, use is also a count, can not reflect the actual role of Partitioner, but in the actual production, the use of partitioner abound

Using Partitioner in Spark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.