"groupBy" and "map" with "first" resulting in SlickException

345 views
Skip to first unread message

teo danciu

unread,
Apr 7, 2014, 10:13:47 AM4/7/14
to scala...@googlegroups.com
Hi,

I'm facing a problem similar to a closed bug (groupBy broken: No type for symbol s2 found in Col1).

In FirstExample of  slick-examples (master), I've added this:
val q: Map[String, Int] = coffees.groupBy(_.name).map { case (n, c) => (n, c.first._2)}.toMap

Running the class results in a stacktrace similar to the one shown in the bug description (below).

It feels like the call to "first" is the issue? (since I've used groupBy and map before without problems)
In my code, I'm retrieving the whole Seq and use .head to simulate the above query, but is there another way to achieve this with loading only the first result and without getting this exception?
 
Thanks!

Teo


scala.slick.SlickException: No type for symbol s2 found for Ref s2
at scala.slick.ast.Ref.nodeWithComputedType2(Node.scala:481)
at scala.slick.ast.Ref.nodeWithComputedType2(Node.scala:475)
at scala.slick.ast.Node$class.nodeWithComputedType(Node.scala:110)
at scala.slick.ast.Ref.nodeWithComputedType(Node.scala:475)
at scala.slick.ast.SimplyTypedNode$$anonfun$4.apply(Node.scala:123)
at scala.slick.ast.SimplyTypedNode$$anonfun$4.apply(Node.scala:123)
at scala.slick.ast.Util$$anonfun$mapOrNone$1.apply(Util.scala:15)
at scala.slick.ast.Util$$anonfun$mapOrNone$1.apply(Util.scala:14)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.slick.ast.Util$.mapOrNone(Util.scala:14)
at scala.slick.ast.Node$class.nodeMapChildren(Node.scala:42)
at scala.slick.ast.Select.nodeMapChildren(Node.scala:454)
at scala.slick.ast.SimplyTypedNode$class.nodeWithComputedType2(Node.scala:123)
at scala.slick.ast.Select.nodeWithComputedType2(Node.scala:454)
at scala.slick.ast.Select.nodeWithComputedType2(Node.scala:454)
at scala.slick.ast.Node$class.nodeWithComputedType(Node.scala:110)
at scala.slick.ast.Select.nodeWithComputedType(Node.scala:454)
at scala.slick.compiler.InferTypes$$anonfun$apply$1.apply(InferTypes.scala:12)
at scala.slick.compiler.InferTypes$$anonfun$apply$1.apply(InferTypes.scala:11)
at scala.slick.compiler.CompilerState.map(QueryCompiler.scala:144)
at scala.slick.compiler.InferTypes.apply(InferTypes.scala:11)
at scala.slick.compiler.QueryCompiler$$anonfun$runPhase$1.apply(QueryCompiler.scala:55)
at scala.slick.compiler.QueryCompiler$$anonfun$runPhase$1.apply(QueryCompiler.scala:54)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
at scala.slick.ast.SymbolNamer.use(Symbol.scala:101)
at scala.slick.compiler.QueryCompiler.runPhase(QueryCompiler.scala:54)
at scala.slick.compiler.QueryCompiler$$anonfun$run$2.apply(QueryCompiler.scala:46)
at scala.slick.compiler.QueryCompiler$$anonfun$run$2.apply(QueryCompiler.scala:46)
at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableOnce$class.foldLeft(TraversableOnce.scala:144)
at scala.collection.AbstractTraversable.foldLeft(Traversable.scala:105)
at scala.slick.compiler.QueryCompiler.run(QueryCompiler.scala:46)
at scala.slick.compiler.QueryCompiler.run(QueryCompiler.scala:41)
at scala.slick.driver.JdbcProfile$LowPriorityImplicits$class.queryToAppliedQueryInvoker(JdbcProfile.scala:42)
at scala.slick.driver.JdbcProfile$$anon$1.queryToAppliedQueryInvoker(JdbcProfile.scala:25)
at com.typesafe.slick.examples.lifted.FirstExample$$anonfun$4$$anonfun$6.apply(FirstExample.scala:77)
at com.typesafe.slick.examples.lifted.FirstExample$$anonfun$4$$anonfun$6.apply(FirstExample.scala:77)
at scala.slick.lifted.Query$$anonfun$map$1.apply(Query.scala:31)
at scala.slick.lifted.Query$$anonfun$map$1.apply(Query.scala:31)
at scala.slick.lifted.Query.flatMap(Query.scala:25)
at scala.slick.lifted.Query.map(Query.scala:31)
at com.typesafe.slick.examples.lifted.FirstExample$$anonfun$4.apply(FirstExample.scala:77)
at com.typesafe.slick.examples.lifted.FirstExample$$anonfun$4.apply(FirstExample.scala:42)
at scala.slick.backend.DatabaseComponent$DatabaseDef$class.withSession(DatabaseComponent.scala:31)
at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$5.withSession(JdbcBackend.scala:61)
at com.typesafe.slick.examples.lifted.FirstExample$delayedInit$body.apply(FirstExample.scala:41)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at com.typesafe.slick.examples.lifted.FirstExample$.main(FirstExample.scala:11)
at com.typesafe.slick.examples.lifted.FirstExample.main(FirstExample.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)



Christopher Vogt

unread,
Apr 7, 2014, 3:29:18 PM4/7/14
to scala...@googlegroups.com

> <https://github.com/slick/slick-examples> (master), I've added this:
> val q: Map[String, Int] = coffees.groupBy(_.name).map { case (n, c) =>
> (n, c.first._2)}.toMap

.first executes a query. Here you call it on a group within a groupBy
statement, which does not make much sense

We could try to catch this statically or throw an exception for this
mistake: https://github.com/slick/slick/issues/754

We don't have an equivalent of .first for queries yet, but it would make
sense: https://github.com/slick/slick/issues/755

Chris


Christopher Vogt

unread,
Apr 7, 2014, 3:30:08 PM4/7/14
to scala...@googlegroups.com

> We don't have an equivalent of .first for queries yet, but it would make
> sense: https://github.com/slick/slick/issues/755

as a workaround you can use .max, but it only works for scalar values,
not composite ones.
Reply all
Reply to author
Forward
0 new messages