These are chat archives for nrinaudo/kantan.csv

1st
Nov 2018
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 14:11
I’m away from my computer for a few days but will take a look as soon as I get back!
Jeff Stice-Hall
@zenchicken
Nov 01 2018 14:11
No problem! Thank you
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 17:11
Oh hang on
Your decoder is defined in the case class, not its companion object
Not sure why it materialises as a null pointer, but there’s a circular dependency issue there
Jeff Stice-Hall
@zenchicken
Nov 01 2018 17:13
Him, shouldn’t be inside of case class at all; should be “top-leve” to the CacuIds object
but if that’s attaching the defn of userDecoder to the case class, I could see where that makes trouble
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 17:36
Not sure what you mean, but move your decoder outside of the case class, or in the case class’ companion object, and your code should work
Jeff Stice-Hall
@zenchicken
Nov 01 2018 17:37
let me give a few things a try and I’ll follow up; thank you for the sanity check
Jeff Stice-Hall
@zenchicken
Nov 01 2018 19:17
Ah, I think the indention of the file mislead a bit. I’ve tried moving the case class defn outside of the object for a bit more clarity. It doesn’t appear to have any effect on the exception. The implicit val is part of the object CacuIds … not part of case class User.
import java.io.File
import java.time.LocalTime

import kantan.csv._
import kantan.csv.ops._

import scala.io.Source
//import kantan.csv.generic._
import kantan.csv.java8._

case class User(id: String, username: String, firstName: Option[String], lastName: Option[String], email: Option[String], fedUserName: Option[String], createdTimestamp: LocalTime)

object CacuIds extends App {

  implicit val userDecoder: RowDecoder[User] = RowDecoder.ordered { (i: String, u: String, f: Option[String], l: Option[String], e: Option[String], s: Option[String], ts: Long) =>
    User.apply(i, u, f, l, e, s, LocalTime.ofSecondOfDay(ts / 1000))
  }

  def sourceFile(path:String) = new java.io.File(path)
  def parse(data:File) = data.asCsvReader[User](rfc)

  override def main(args: Array[String]): Unit = {
    val data = sourceFile("/Users/jsh/Downloads/output.2018-10-30T00_16_05.186234.csv")
    val rows = parse(data)
    rows.foreach(println)
  }
}
NPE still occurs at same call site.
Was the suggestion you were making to move userDecoder into companion object of User?
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 20:46
alright, let me have a proper look then.
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 20:52
I can reproduce the error. Something's really weird, you're right
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 20:59
Ah, got it. That's a nasty one
alright, so you're using a deprecated API: main when extending App. Part of the reason it's deprecated is because it yields exactly what you're observing: when main is called, userDecoder is not yet initialised, so you while you do have an implicit decoder with the right type in scope, its value is still null at the time it's needed
just drop the main method, dump its content in the body of CacuIds and everything should work fine
it fixes the issue on my local env anyway
Jeff Stice-Hall
@zenchicken
Nov 01 2018 21:53
Oh gross! That was just for a quick PoC. Ok, I will try that and check it out. Thank you for your feedback. The library is quite slick :)
Nicolas Rinaudo
@nrinaudo
Nov 01 2018 21:55
Glad I could help, and thanks, I'm proud of it, a little bit :)