Detailed introduction to the countByKey operator in Spark

insert image description here

1. Detailed introduction to the countByKey operator in Spark

For the task of wordcount, we used reduceByKeyto aggregate the values ​​of the same key to obtain the value corresponding to each key. This article will introduce another more convenient operator, which will directly countByKeyreturn the value corresponding to each key. How many values ​​are there, returned in the form of map.

1. Function introduction

In Spark, countByKeyit is an action operator (Action Operator) used to operate RDD of key-value pairs. It is used to count the number of elements corresponding to each key, and returns a map (Map) representing the number of elements corresponding to each key.

grammar:

 

Guess you like

Origin blog.csdn.net/m0_47256162/article/details/132353996