Type cast output from Slick

71 views
Skip to first unread message

Rennoi Samuel

unread,
Feb 13, 2015, 10:56:37 AM2/13/15
to scala...@googlegroups.com
with:

    val sumq =
      products.groupBy(p => (p.profile_id, p.product_id)).map {
        case ((profid, prodid), ps) => (prodid, profid, ps.map(_.price).max)
      }.sortBy(_._3)


I can only do 

    for(f<-sumq) 
    {
          println(f._1+" "+f._2+" "+f._3)
    }

How can I get named values as 

    for(f<-sumq) 
    {
          println(f.profid+" "+f._prodid+" "+f._ps)
    }


Thanks

Pedro Furlanetto

unread,
Feb 14, 2015, 10:40:39 AM2/14/15
to scala...@googlegroups.com
You can map your result to a case class with these properties.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Slick / ScalaQuery" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalaquery+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scalaquery/a0a5844e-73da-4157-88a2-bc8f879cd320%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

virtualeyes

unread,
Feb 15, 2015, 4:13:53 AM2/15/15
to scala...@googlegroups.com
So cumbersome, _._N syntax.

Hopefully on the DSL front something closer to LINQ will arise with named accessors (e.g. the rejected comprehensive comprehensions proposal) threaded through for yield.

Christopher Vogt

unread,
Feb 15, 2015, 6:51:50 AM2/15/15
to scala...@googlegroups.com
I am working on an extensible records implementation for Scala.
I'll see if I can make it work with Slick until Scala Days.

https://github.com/cvogt/records/blob/0.1/src/test/scala/RecordTest.scala#L56

Tentative name: "Scala XR".

Chris
> > email to scalaquery+...@googlegroups.com <javascript:>.
> <https://groups.google.com/d/msgid/scalaquery/a0a5844e-73da-4157-88a2-bc8f879cd320%40googlegroups.com>.
>
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Slick / ScalaQuery" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scalaquery+...@googlegroups.com
> <mailto:scalaquery+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com
> <https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com?utm_medium=email&utm_source=footer>.

Naftoli Gugenheim

unread,
Feb 15, 2015, 10:49:36 PM2/15/15
to scala...@googlegroups.com
That name might be confused with https://github.com/harrah/browse

--

---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/54E08854.8030304%40gmail.com.

virtualeyes

unread,
Feb 16, 2015, 6:59:11 AM2/16/15
to scala...@googlegroups.com
Interesting, Chris, that would be a huge improvement if Slick users did not have to repeat table aliases case-matching through query phases.

Thanks for the link, looking at the sources now (macros, no surprise there ;-))

Christopher Vogt

unread,
Feb 17, 2015, 2:16:50 AM2/17/15
to scala...@googlegroups.com
Yep, macros ;). Currently the record types are encoded in tuples
combined using "with". I am thinking about changing to using structural
types instead. I think I should be able to allow SELECTing fields
(key+value) out of records as well as merging records this way using
only black-box macros, which would allow code-completion in IntelliJ
(and of course eclipse/ensime). Other things like renaming or removing
fields will require white-box macros. Macros should allow to have
structural types only at compile time and no reflection overhead.

We'll see. I am optimistic.

Chris
> > an email to scalaquery+...@googlegroups.com <javascript:>
> > <mailto:scalaquery+...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com
> <https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com>
>
> >
> <https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/scalaquery/daaacf08-2e1a-4fbf-ae4e-6fee1dadc6d0%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Slick / ScalaQuery" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scalaquery+...@googlegroups.com
> <mailto:scalaquery+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scalaquery/f284ba37-6429-4c64-8761-55b22c71fea0%40googlegroups.com
> <https://groups.google.com/d/msgid/scalaquery/f284ba37-6429-4c64-8761-55b22c71fea0%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages