score:3
Accepted answer
you need to group your result by post, author and receiver and the map to aggregate the comments by just counting them.
val posts = (for {
p <- posts.query if p.receiver === userid
comment <- comments.query if comments.postid === p.id
author <- users.query if p.author === author.id
receiver <- users.query if p.receiver === receiver.id
} yield (p, comment, author, receiver)) //so far thats your current query
.groupby({ //group by post, author and receiver
case (post, comment, author, receiver) =>
(post, author, receiver)
})
.map({ //aggregate your comments (second argument in tuple) and count them
case ((post, author, receiver), list) => {
(post, author, receiver, list.map(_._2).count))
}
})
on mobile currently so this probably won't compile, but you should get the idea.
Source: stackoverflow.com
Related Query
- Scala Slick 3: Count Rows and get row
- Scala : Passing elements of a Dataframe from every row and get back the result in separate rows
- Get WrappedArray row valule and convert it into string in Scala
- Split multiple fields or columns of a single row and create multiple rows using Scala
- how to get multiple rows from one row in spark scala
- How would I get the row wise count of a string match and add it as a new column in Scala?
- groupBy and get count of records for multiple columns in scala
- Scala Spark Convert Dataframe and get all Unique IDs and its type from each row
- How to get distinct value, count of a column in dataframe and store in another dataframe as (k,v) pair using Spark2 and Scala
- Scala Slick 3.0 Creating Table and then Inserting Rows
- how to get virtual user number, iteration number and total virtual users count during runtime in Gatling Scala script?
- Spark Scala Compare Row and Row of 2 Data frames and get differences
- Generate a output string, while rows dependent on another row in Spark and Scala
- Scala Divide two integers and get a float result
- Slick 3.0 Insert and then get Auto Increment Value
- get min and max from a specific column scala spark dataframe
- Get head item and tail items from scala list
- How to get logging working in scala unit tests with testng, slf4s, and logback
- How to create annotations and get them in scala
- Updating db row scala slick
- Scala Get First and Last elements of List using Pattern Matching
- How to get all request parameters in Play and Scala
- Mapping Between Enumeration on Scala and Slick
- How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.0?
- How to correctly get current loop count from a Iterator in scala
- Slick join two tables and get result of both
- Get the row corresponding to the latest timestamp in a Spark Dataset using Scala
- How to fold a Scala iterator and get a lazily evaluated sequence as result?
- Count rows with Slick 1.0.0
- Async before and after for creating and dropping scala slick tables in scalatest
More Query from same tag
- Errors during maven install when adding spark-hive_2.10 dependency in maven
- Iterate with hasNext() and next() over an asynchronously generated stream of elements
- Is AWS SDK `PutObjectResult` metadata not holding the content length value?
- Scala failing to resolve a type mismatch problem in a complicated code
- Problems using Nothing bottom type while trying to create generic zeros for parametrized monoids
- Scala: Why asInstanceOf can accept a type parameter but isInstanceOf can not?
- How do I add Builder methods to a custom IndexedSeq in Scala?
- Searching for Terms and Printing lines in a Text File
- Scala - flatMap
- How to dump contents of a Java library to the console?
- How does Pyspark decides data type of a column automatically when inferschema is set to True, What happens in the background
- Usage example of scalaz-stream's inflate
- Inferred type in for comprehension
- Play modules test & FakeApplication
- Play framework, scala forms set default value
- Not able to extract values in Gatling
- Unclear CORS filter in Play
- Finding the Value of a Map where the key is a regex
- Does scala have shortcuts for functional objects?
- Apache SPARK SVM in Scala vs Python
- Using IntelliJ, how can i determine whether particular function stems from Java or Scala
- Timescale missing on the module as other modules have it Verilator error
- Delete child documents without parent in Elasticsearch using Jest
- Pass arguments to a udf from columns present in a list of strings
- Convert JSON from a URL to dataframe (Pyspark and Scala)
- Type mismatch, expected ((Double,Double))=>Boolean, actual ((Double,Double))=>Any
- Scala error - error: not found: type
- How could an idiomatic design of Serializable/Cloneable/... look like in Scala?
- Parsing line-based structure (ray tracer) without using too many vars
- Convert Array into dataframe with columns and index in Scala