scala-csv-parser icon indicating copy to clipboard operation
scala-csv-parser copied to clipboard

Column limit

Open mnn opened this issue 7 years ago • 2 comments

There seems to be a limit on how many columns can be parsed which I don't see mentioned in documentation.

My case class:

private case class DeckLevelDescriptorFromCsv(
                                               levelId: Int,
                                               isHuman: Boolean,
                                               playerIndexInTeam: Int,
                                               avatarId: Int,
                                               frameId: Int,
                                               card01Id: Int,
                                               card01Count: Int,
                                               card02Id: Int,
                                               card02Count: Int,
                                               card03Id: Int,
                                               card03Count: Int,
                                               card04Id: Int,
                                               card04Count: Int,
                                               card05Id: Int,
                                               card05Count: Int,
                                               card06Id: Int,
                                               card06Count: Int,
                                               card07Id: Int,
                                               card07Count: Int,
                                               card08Id: Int,
                                               card08Count: Int,
                                               card09Id: Int,
                                               card09Count: Int,
                                               card10Id: Int,
                                               card10Count: Int,
                                               card11Id: Int,
                                               card11Count: Int,
                                               card12Id: Int,
                                               card12Count: Int,
                                               card13Id: Int,
                                               card13Count: Int,
                                               card14Id: Int,
                                               card14Count: Int,
                                               card15Id: Int,
                                               card15Count: Int,
                                               card16Id: Int,
                                               card16Count: Int,
                                               card17Id: Int,
                                               card17Count: Int,
                                               card18Id: Int,
                                               card18Count: Int,
                                               card19Id: Int,
                                               card19Count: Int,
                                               card20Id: Int,
                                               card20Count: Int
                                             )

reading:

      val parsedDecks = Parser.parse[DeckLevelDescriptorFromCsv](decksFileContent)

error:

error: value and is not a member of zamblauskas.functional.ApplicativeBuilder22[zamblauskas.csv.parser.ColumnReads,Int,Boolean,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int]
[ant:scalac]       val parsedDecks = Parser.parse[DeckLevelDescriptorFromCsv](decksFileContent)
[ant:scalac]                                                                 ^
[ant:scalac] <macro>:1: error: implementation restricts functions to 22 parameters
[ant:scalac] new tk.purplegames.shaeloarena.gui.screens.levelSelection.DeckLevelDescriptorFromCsv(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)
[ant:scalac] ^

I have also tried defining ColumnReads:

      implicit val deckRead: ColumnReads[DeckLevelDescriptorFromCsv] = (
        column("levelId").as[Int] and
          column("isHuman").as[Boolean] and
          column("playerIndexInTeam").as[Int] and
          column("avatarId").as[Int] and
          column("frameId").as[Int] and
          column("card01Id").as[Int] and
          column("card01Count").as[Int] and
          column("card02Id").as[Int] and
          column("card02Count").as[Int] and
          column("card03Id").as[Int] and
          column("card03Count").as[Int] and
          column("card04Id").as[Int] and
          column("card04Count").as[Int] and
          column("card05Id").as[Int] and
          column("card05Count").as[Int] and
          column("card06Id").as[Int] and
          column("card06Count").as[Int] and
          column("card07Id").as[Int] and
          column("card07Count").as[Int] and
          column("card08Id").as[Int] and
          column("card08Count").as[Int] and
          column("card09Id").as[Int] and
          column("card09Count").as[Int] and
          column("card10Id").as[Int] and
          column("card10Count").as[Int] and
          column("card11Id").as[Int] and
          column("card11Count").as[Int] and
          column("card12Id").as[Int] and
          column("card12Count").as[Int] and
          column("card13Id").as[Int] and
          column("card13Count").as[Int] and
          column("card14Id").as[Int] and
          column("card14Count").as[Int] and
          column("card15Id").as[Int] and
          column("card15Count").as[Int] and
          column("card16Id").as[Int] and
          column("card16Count").as[Int] and
          column("card17Id").as[Int] and
          column("card17Count").as[Int] and
          column("card18Id").as[Int] and
          column("card18Count").as[Int] and
          column("card19Id").as[Int] and
          column("card19Count").as[Int] and
          column("card20Id").as[Int] and
          column("card20Count").as[Int]
        ) (DeckLevelDescriptorFromCsv)

which resulted in:

error: value and is not a member of zamblauskas.functional.ApplicativeBuilder22[zamblauskas.csv.parser.ColumnReads,Int,Boolean,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int]

I'll probably change the file format (perhaps join card id and count), but I thought it would be good to write it here, so others are aware of this limitation. Case classes are no longer limited by 22, but other things are (I think tuples and functions, not sure though).

mnn avatar Nov 08 '17 13:11 mnn

Hey,

I think the only place there it is limited is on the template https://github.com/zamblauskas/scala-csv-parser/blob/master/src/main/boilerplate/zamblauskas/functional/Applicative.scala.template

If you aren't afraid to get your hands dirty, you can try bumping 21/22 to some higher value.

I'll try to find time to look into this a bit later.

zamblauskas avatar Nov 08 '17 15:11 zamblauskas

Two problems (at least) with > 22 params.

  1. My macro implementation needs the SomeClass.apply(_,_,_,.....) which is only available upto 22 params, hence the <macro>:1: error: implementation restricts functions to 22 parameters error
  2. I need FunctionN.curried for the Applicative.mapN implementation, there's only Function22 of course.

I don't see any easy or user friendly way to overcome this.

Maybe refactoring internals to use intermediate representation of Shapeless HList would help here. Which is an interesting exercise, but not in the nearest future :)

zamblauskas avatar Nov 08 '17 16:11 zamblauskas