score:5
Accepted answer
Sure.
val rdd = sc.parallelize(Array(("foo", (1, 10)), ("foo", (2, 2)), ("bar", (5, 5))))
val res = rdd.reduceByKey((p1, p2) => (p1._1 + p2._1, p1._2 + p2._2))
res.collect()
Source: stackoverflow.com
Related Query
- Spark - Best way agg two values using ReduceByKey
- Best way to merge two maps and sum the values of same key?
- Spark : Average of values instead of sum in reduceByKey using Scala
- Join two dataframes and replace the original column values using Spark Scala
- Best way to gain performance when doing a join count using spark and scala
- What is the best way to create Spark DataFrames using Spark Testing Base library?
- Replace Not null values of Spark dataframe as “1” using Scala in optimized way
- Fetching distinct values on a column using Spark DataFrame
- Using reduceByKey in Apache Spark (Scala)
- What is the best way to perform OAuth2 authentication using akka-http?
- Is there a way to filter a field not containing something in a spark dataframe using scala?
- Is there a way to merge two or more .dex files into one .dex file using Scala?
- What is the best way to implement a request/response protocol using akka and scala?
- spark programming: best way to organize context imports and others with multiple functions
- Is it possible to ignore null values when using lead window function in Spark
- What is the best way to deal with compsite keys when using Salat with MongoDB?
- spark RDD sort by two values
- Using regexp to join two dataframes in spark
- Proper way to make a Spark Fat Jar using SBT
- Best way to create a login/logout form in Scala using Lift
- Writing files to S3 using spark and scala is extremely slow. What is a better way to optimize this?
- What is the best way to avoid clashing between two typeclass definitions in shapeless
- Best way to represent constraints on values in Scala?
- Cast values of a Spark dataframe using a defined StructType
- What is the best way to get the last inserted auto-generated ID using slick?
- Best way to extract a node and all of its children using scala.xml.pull?
- Sum up into a new column from a range of values of a column in Spark using Scala
- Writing CSV file using Spark and scala - empty quotes instead of Null values
- How to union two tables and remove duplicates with conditions using Spark
- What's the best way using Scala and SBT to create samples for a library that can be built from the SBT CLI?
More Query from same tag
- how to fix task not serializable exception in sparkstreaming
- Scala deep type cheking
- Install sbt on ubuntu
- Move Zeroes in Scala
- Why are List and String identifiers named "xs" (in Scala and other languages)?
- Scala boilerplate: lack of common superclass of Iterable and ParIterable
- Why is VectorBuilder in the package scala.collections.immutable?
- Scala Cats async functor
- How Can I parse a request uri containing specific word
- Mercurial Eclipse: See changes outside of project directories
- Haskell GHCi prints lazy sequence but Scala REPL doesn't
- Scala: Implicit parameter resolution precedence
- compareTo type error
- scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result
- Is it possible to convert a TypeTag to a Manifest?
- How to prevent an action from running if json payload is too large
- How to pass the dynamic exposed port in container to my application?
- How to generate OpenPGP KeyPair without passphrase using BouncyCastle?
- Unknown UID warning when passing message to remote actor
- How to trick Scala to not find duplicate implicits for Nothing
- Using @BeanProperty or Create Set & Get methods using scala
- Play framework check whether a key exists
- Play framework templates: how to start a new row in a table?
- Pivot scala dataframe with conditional counting
- Maven Assembly Plugin Merge Strategy
- Scala js Jquery offset result how to use?
- How to pass 2 bytes string without being garbled in Groovy Script Engine?
- Convert tuple to case class with default values
- Connection pool is not initialized in unit test with scalikejdbc 2.4.1
- How do I make intellij Idea to highlight Scala script correctly with #! (shebang)