Skip to content

Instantly share code, notes, and snippets.

@lihaoyi
Last active May 22, 2020 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lihaoyi/8fdc393a800153025e9b359fbba1b40b to your computer and use it in GitHub Desktop.
Save lihaoyi/8fdc393a800153025e9b359fbba1b40b to your computer and use it in GitHub Desktop.
import $ivy.`io.getquill::quill-jdbc:3.5.1`, io.getquill._
val ctx: PostgresJdbcContext[LowerCase.type] = ???
import ctx._
case class CountryLanguage(countryCode: String,
language: String,
isOfficial: Boolean,
percentage: Double)
case class City(id: Int,
name: String,
countryCode: String,
district: String,
population: Int)
val popularLanguages = ctx.run(
query[City]
.join(query[CountryLanguage])
.on { case (city, language) => city.countryCode == language.countryCode }
.groupBy { case (city, language) => language }
.map{case (language, cityLanguages) => (language, cityLanguages.size)}
.sortBy{case (language, cityCount) => (language, -cityCount)}
.take(5)
)
pprint.log(popularLanguages)
// java.lang.IllegalStateException:
// The monad composition can't be expressed using applicative joins.
// Faulty expression: '(x01, x11).size'. Free variables: 'List(x01, x11)'.
// at io.getquill.util.Messages$.fail(Messages.scala:43)
// at io.getquill.context.sql.idiom.SqlIdiom.$anonfun$translate$1(SqlIdiom.scala:43)
// at scala.Option.map(Option.scala:242)
// at io.getquill.context.sql.idiom.SqlIdiom.translate(SqlIdiom.scala:43)
// at io.getquill.context.sql.idiom.SqlIdiom.translate$(SqlIdiom.scala:33)
// at io.getquill.PostgresDialect$.translate(PostgresDialect.scala:43)
// at io.getquill.context.ContextMacro.translateStatic(ContextMacro.scala:51)
// at io.getquill.context.ContextMacro.translate(ContextMacro.scala:37)
// at io.getquill.context.ContextMacro.expand(ContextMacro.scala:24)
// at io.getquill.context.ContextMacro.expand$(ContextMacro.scala:21)
// at io.getquill.context.QueryMacro.expand(QueryMacro.scala:8)
// at io.getquill.context.QueryMacro.expandQueryWithMeta(QueryMacro.scala:184)
// at io.getquill.context.QueryMacro.expandQuery(QueryMacro.scala:51)
// at io.getquill.context.QueryMacro.runQuery(QueryMacro.scala:34)
//
// val popularLanguages = ctx.run(
// ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment