Tag: scala

  • Principles of Reactive Programming

    This year I’ve attended Principles of Reactive Programming course. It wasn’t easy one, at least for me.

    I mean, first two weeks driven by Martin were clear and straightforward. Even first Erik’s week about Future was approachable. The rest -rxScala with it’s Observables and actor model with Akka was rather hard and required a lot of work. My conclusion: akka isn’t easy concept (contrary to all akka guides saying it is) maybe it’s easier to debug when things go bad comparing to standard java locking/synchronisation model but for designing it requires a lot of time and hard work to acquire that way of thinking.
    Except videos on course pages I red other helpful materials like:

    1. Learning Concurrent Programming in Scala book by Aleksandar Prokopec
    2. The Neophyte’s Guide to Scala

    and two cheet sheets dedicated for this course

    1. by sjuvekar
    2. by dnvriend

    And good akka tutorials

    1. Concurrency and Fault Tolerance Made Easy: An Akka Tutorial with Examples by Diego Castorina
    2. Reactive twitter app with akka by Jan Machacek
    3. Implementing the Reactive Manifesto with Akka by Adam Warski – video

    Maybe someday that materials would help you.

  • Scalar conference review

    Scalar conference review

    Scalar Conference is the first free to attend scala conference. At least first in central Europe I know.

    I had a pleasure to be a part of it as an attendee and a listener. I must say it was well organized. The organizers –  Softwaremill – top notch software house from Warsaw – proved that are real professionals in this matter. There was up to 300 attendees. The atmosphere was amazing because of many reasons: subjects were great, I met many friends and the most important I am just in the middle of a transfer from Allegro to Softwaremill :) You can imagine that I was very excited by meeting my new colleagues!

    This was the one of those conferences where polish speakers were much more better than abroad guests.

    • Tomek Nurkiewicz is fully professional stage beast. His english is just as he was born in Birmingham Palace. He was talking about dark sides of scala, some complex notations and implementations of standard library.
    • Adam Warski is second great presenter, experienced in giving lectures in english. Adam was talking about spray.io – it looked to me as micro-framework in scala, I’ve already know a few in other languages – ratpack in groovy, flask, bottle in python, express in nodejs – all are very super tools!
    • Then comes Konrad Malawski I know he is Pole but listening to him you are sure he comes from Chelsea – a district of Kraków or maybe London. Konrad pretends to me as a hardworking guy. He became a Akka developing team member. He was talking about persistence in akka world – you might want to persists Actor’s mailboxes.
    • Grzegorz Kossakowski was a Typesafe star on scalar.  On daily basis he is scala compiler developer. He proved why java8 lambas being implemented on top of invokedynamic are not faster then those from scala being implemented on classsical java approach – anonymous class implementing interface with one method.
    • Very interesting guys from ICM presting hadoop + scala, scoobi and scalding frameworks for hadoop. What inspired me the most was the scala REPL for hadoop.
    • And there was Łukasz Kuczera with presentation on scalaz – functional library to scala.

    All above were very interesting. Guys were prepared and I was focused all time and understood everything.

    • Grzegorz Kubiak had a great topic but I think he didn’t practise before exhibition.
    • Stefan Zegier was correct talking about slick – it look for me as a orm in scala.
    • Jon Pretty crazy guy was funny but might be misunderstood by most with his algebra proofs :)
    • Mathias Nehlsen didn’t treat poles seriously or maybe  he did just boring presentation. And the two worst presentation where underscore magic – underscore in scala? come on! we’ve got scala compiler developer on place! and macro based type providers in scala… no code, no examples – no reward. I still don’t know what are type providers — totally a waste of time.

    After that amazing conference I went to after party with friends from Allegro, Polidea and Javeo where I met all other colleges from Softwaremill. That was a great time. I hope that Pedrowaty a chef of solution architects in Allegro (he was present on conference) changed his mind about scala – it’s not a dead end any more. This is a great article about Transitioning to scala.

    The conference was free but with this high quality I would really not bother to pay for it.

  • Cascading Tube

    Usage example of Cascading Tube

    EXAMPLE I
    Step 0 is pure cascading flow example Cascading.

    Step 0.

    Short description of method: it takes logs from one source and produces tree different reports

    public FlowDef flow(Tap pv, Tap trans, Tap transToFirstSource, Tap transToLastSource, Tap transDistributedAmongSources) {
    // agregation
    Pipe transPipe = new Each("trans", new Fields("t_quantity", "t_itemCost"), new ExpressionFunction(new Fields("t_income"),
    "(double) t_quantity * (double) t_itemCost", Double.class), Fields.ALL);
    transPipe = new AggregateBy(transPipe, new Fields("t_userId", "t_transactionId"), new FirstBy("t_createTime"),
    new SumBy(new Fields("t_quantity"), new Fields("t_quantity"), Integer.class),
    new SumBy(new Fields("t_income"), new Fields("t_income"), Double.class));
    
    // divide
    Pipe pvPipe = new Pipe("pv");
    pvPipe = new GroupBy(pvPipe, new Fields("p_userId"), new Fields("p_createTime"));
    Pipe visitPipe = new Every(pvPipe, new GetVisit(selfReferred()), Fields.RESULTS);
    
    // merge
    Pipe crossTransWithVisits = new CoGroup(visitPipe, new Fields("p_userId"), transPipe, new Fields("t_userId"));
    crossTransWithVisits = new Each(crossTransWithVisits, new Fields("start", "t_createTime"), new OlderThan());
    crossTransWithVisits = new Checkpoint(crossTransWithVisits);
    
    return FlowDef.flowDenew Fields().setName("ConversionAttribution").addSource(pvPipe, pv).addSource(transPipe, trans)
    .addTailSink(assignTransactionToFirstVisit(crossTransWithVisits), transToFirstSource)
    .addTailSink(assignTransactionToVisit(crossTransWithVisits), transToLastSource)
    .addTailSink(distributeTransactionAmongVisits(crossTransWithVisits), transDistributedAmongSources);
    }

    |
    |
    |
    |
    \/

    Step 1a.

    You can shorten your code by adding helper class with and use “f(_)” instead of “new Fields(_)”:

    static public Fields f(String... names) {
    return new Fields(names);
    }
    
    static public SumBy sum(String field, Class<?> resultType) {
    return new SumBy(f(field), f(field), resultType);
    }
    
    static public SumBy sum(String field) {
    return sum(field, Double.class);
    }
    
    static public SumBy sumInt(String field) {
    return sum(field, Integer.class);
    }
    
    static public CountBy count(String outField) {
    return new CountBy(f(outField));
    }

    replacing

    new Fields(_) == > f(_)
    new FirstBy(field) == > first(field)
    new SumBy(new Fields("t_quantity"), new Fields("t_quantity"), Integer.class) == > sumInt("t_quantity")
    new SumBy(new Fields("t_income"), new Fields("t_income"), Double.class) == > sum("t_income")

    —– OR
    |
    |
    |
    \/

    Step 1b.

    Or you can try to use Cascading Tube wrapper, that implements builder pattern upon cascading and makes your code shorter, concise, readable and intuitive?

    (This method does exactly same thing as that above – it’s only rewritten to “Cascading Tube”)
    Add some imports first

    import jj.tube.Aggregators._
    import jj.tube.Io._
    import jj.tube.Tube._
    import jj.tube._

    and put this method into your class

    def flow(pv: Io, trans: Io, transToFirstSource: Io, transToLastSource: Io, transDistributedAmongSources: Io, transTrap: Io, pvTrap: Io) = {
    val transPipe = Tube("trans")
    .multiply("t_quantity", "t_itemCost", "t_income")
    .aggregateBy(("t_userId", "t_transactionId"), first("t_createTime"), sumInt("t_quantity"), sum("t_income"))
    
    val pvPipe = Tube("pv")
    .groupBy("p_userId", "p_createTime")
    .every(buffer = new GetVisit(selfReferred))
    
    val crossTransWithVisits = Tube("crossVisitAndTrans", pvPipe).coGroup("p_userId", transPipe, "t_userId", new RightJoin)
    .discard("p_userId")
    .groupBy(("t_userId", "t_transactionId"), "start")
    .every(buffer = new FillMisingMatchingVisit)
    .filter(("start", "t_createTime"), new OlderThan)
    .checkpoint
    
    FlowDef.flowDef().setName("ConversionAttribution").addSource(pvPipe, pv)
    .addSource(transPipe, trans)
    .addTailSink(assignTransactionToVisit(crossTransWithVisits, FIRST), transToFirstSource)
    .addTailSink(assignTransactionToVisit(crossTransWithVisits, MATCHING), transToLastSource)
    .addTailSink(distributeTransactionAmongVisits(crossTransWithVisits), transDistributedAmongSources)
    .addTrap("trans", transTrap)
    .addTrap("pv", pvTrap)
    }

    Which one do you like to read more?

  • so little time…

    And so many ideas. I have found an interesting reading nathanmarz.com. I was just seeking some hadoop related solution and found that guy. Looks interesting, so I will follow his twitts for a while.

    • I use feedly instead of google reader, I hate it on my mobile when it comes to run it first time after upgrade, it always asks me to login to google reader, I don’t know how this will end
    • I am almost ready with scala course from coursera, even though I don’t feel comfortable with scala. I tried to modify playframework scala todolist and failed with that “syntactic sugar”. [my scala play todolist]
    • As we are adopting Cascading into our project (We believe it will replace apache pig for our mapreduce computations) I finished “learn.cascading” — (link in cascading documentation page) there are given test in junit and you are asked to write an implementation for it — exactly as in groovy-koans. [Cascading isn’t as intuitive as pig but running it’s “ultrafast” tests -comparing to pigunit- makes it worth spending time on it. We use cloudera distro of hadoop and in latest CDH4.2.1 there is still pig in version 0.10, maybe pig current apache stable version 0.11 tests run faster?]
    • This week I’ve started to use idea ide, I was a big fun of netbeans working in Orange, I am fun of sts eclipse working in allegro (except the moments its window simply disappears in my mint nadia 14 – I hope it was missing repo or plugin issue) but the eclipse groovy plugin does not highlight unused imports… and idea does.
    • I wish I know how to “keep fire under motivations”. I wish to run something. I wish to participate in something cool. Of course my work is something that kind but still I feel there is a room for more. I am 30 right now and the most important thing I’ve changed in my point of view is about people. It is very important to have great guys around. The only way to build something working fine is to do  it with a team. Take a look on stendi.pl. I thought I am able to build such a shop myself. But I was wrong. I see a great team working on it. I see testers hard work. And I know now how big cost is to build something shiny.
  • WarsawJUG: Clojure, REPL, Eclipse CCW, Eclipse Mylyn

    Two days ago I was participating a WarsawJUG meeting. Jacek Laskowski was speaking about clojure and some other amazing technologies he has learned while dealing with clojure and eclipse. (finally there was a guy that uses netbeans and claims that it worth something, most of the auditorium is eclipse, idea, spring coders – I predict from their’s reaction on: how faster and better is something being done in eclipse/spring whatever…). What really was interesting is clojure itself. I don’t really understand this fashion of clojure, scala – I have to read more about these trends. I’ve been once on meeting with Luc Duponcheel who was convincing ppl to scala and it’s lift framework. He believes it has great future towards, he believes also there will jvm remain after whole java and jee world. I will give these languages some more time, and go around for a while.