These are chat archives for nrinaudo/kantan.csv

13th
Feb 2018
Jules Ivanic
@guizmaii
Feb 13 2018 15:31
Hi
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:31
@guizmaii so about your problem, I'll need more context
Jules Ivanic
@guizmaii
Feb 13 2018 15:31
ok
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:31
I'm not seeing where you declare your Decoder instance, for example - generic derivation?
Jules Ivanic
@guizmaii
Feb 13 2018 15:31
Hum
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:31
ideally, you'd give me some code I can run locally and debug
Jules Ivanic
@guizmaii
Feb 13 2018 15:31
I don’t have any Decoder
    import kantan.csv._
    import kantan.csv.ops._
    import kantan.csv.generic._

final case class TestAddress(line1: String, postalCode: String, town: String, lat: String, long: String)
    object TestAddress {
      def unapply(addr: TestAddress): (Address, LatLong) =
        Address(line1 = addr.line1, line2 = "", postalCode = PostalCode(addr.postalCode), town = addr.town, country = "France") -> LatLong(
          latitude = addr.lat.toDouble,
          longitude = addr.long.toDouble)
    }

    val rawData =
      """
        |Line1;PostalCode;Town;Lat;Long
        |5 BOULEVARD DE LA MADELEINE;75001;PARIS;48.869613;2.327182
        |17 rue Francois Miron;75004;Paris;48.85574;2.357078
        |1 RUE DANTON;75006;PARIS;48.852842;2.342764
        |24 rue dauphine;75006;PARIS;48.854833;2.339308
        |30 PLACE DE LA MADELEINE;75008;PARIS;48.870776;2.325585
        |50 rue du Docteur Blanche;75016;Paris;48.852969;2.264384
        |16 RUE SAINT FIACRE  - 75002 PARIS;75002;PARIS;48.870399;2.345721
        |4 RUE DE SONTAY;75116;PARIS;48.87037;2.284564
        |7 rue Victorien Sardou;75016;Paris;48.843023;2.267556
        |62 avenue des champs elysee;75008;Paris;48.871059;2.305513
        |233 Boulevard Voltaire 75011 Paris;75011;Paris 75011;48.851259;2.391402
        |13 rue Henri Barbusse;92230;GENNEVILLIERS;48.917939;2.296612
        |35 boulevard d'Exelmans;75016;PARIS;48.841579;2.263333
        |95 avenue du General Leclerc;75014;Paris;48.823483;2.325553
        |12 rue de l'Assomption;75016;Paris;48.853383;2.274257
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
      """.stripMargin

    info(s"ERROR RAW: ${rawData}")

    val data = rawData.readCsv[List, TestAddress](rfc.withHeader.withCellSeparator(';'))
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:32
so you're using kantan.csv.generic._ ?
in which case I'd need the imports you're using
Jules Ivanic
@guizmaii
Feb 13 2018 15:32
here is all my code
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:32
let's see...
I'm still lacking some stuff - what's Address and LatLong?
mmm... just noise. It's not used. Ok.
Jules Ivanic
@guizmaii
Feb 13 2018 15:36
In fact @fanf gave me the solution
    val rawData =
      """Line1;PostalCode;Town;Lat;Long
        |5 BOULEVARD DE LA MADELEINE;75001;PARIS;48.869613;2.327182
        |17 rue Francois Miron;75004;Paris;48.85574;2.357078
        |1 RUE DANTON;75006;PARIS;48.852842;2.342764
        |24 rue dauphine;75006;PARIS;48.854833;2.339308
        |30 PLACE DE LA MADELEINE;75008;PARIS;48.870776;2.325585
        |50 rue du Docteur Blanche;75016;Paris;48.852969;2.264384
        |16 RUE SAINT FIACRE  - 75002 PARIS;75002;PARIS;48.870399;2.345721
        |4 RUE DE SONTAY;75116;PARIS;48.87037;2.284564
        |7 rue Victorien Sardou;75016;Paris;48.843023;2.267556
        |62 avenue des champs elysee;75008;Paris;48.871059;2.305513
        |233 Boulevard Voltaire 75011 Paris;75011;Paris 75011;48.851259;2.391402
        |13 rue Henri Barbusse;92230;GENNEVILLIERS;48.917939;2.296612
        |35 boulevard d'Exelmans;75016;PARIS;48.841579;2.263333
        |95 avenue du General Leclerc;75014;Paris;48.823483;2.325553
        |12 rue de l'Assomption;75016;Paris;48.853383;2.274257
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033
        |108 rue de Richelieu;75002;PARIS;48.871369;2.34033""".stripMargin
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:36
the problem is the last empty line
although... that shouldn't be a problem...
Jules Ivanic
@guizmaii
Feb 13 2018 15:36
and the first one too
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:37
not really, it works for me
Jules Ivanic
@guizmaii
Feb 13 2018 15:37
with the first rawData I gave you ?
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:39
sure. I just removed the last empty line and it worked
Jules Ivanic
@guizmaii
Feb 13 2018 15:40
ok strange
It works
thanks for your help and reactivity ! :)
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:41
no worries, this still looks like a bug. Not sure why this last empty line is not skipped
Nicolas Rinaudo
@nrinaudo
Feb 13 2018 15:46
@guizmaii ah, right, I'm an idiot. I should have seen it immediately. By RFC, a trailing line break is legal (see 2.2 here: https://tools.ietf.org/html/rfc4180#page-2)
but in your case, it's not a trailing line break. It's a trailing line break followed by multiple whitespace - or, in other words, a valid CSV row with a single cell
or, in other words: the error you're getting might not be the most explicit in the world, but it's expected
Jules Ivanic
@guizmaii
Feb 13 2018 15:50
interesting ! Thanks again