Code Monkey home page Code Monkey logo

scala-csv-parser's People

Contributors

idctim avatar zamblauskas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

scala-csv-parser's Issues

Parser inside polymorphic methods.

Can I use Parser inside a polymorphic method like this?

  def readCsv [A] (str: String) : Queue[A] = {
    if (!RFile(str).exists) {
      logger.info(s"File not exists: $str")
      return Queue.empty[A]
    }
    val csv = readFileContent(str)
    Parser.parse[A](csv) match {
      case Left(failure: Failure) => {
        logger.error(s"Syntax error: ${failure.message}")
        Queue.empty[A]
      }
      case Right(list: Seq[A]) => list.to(Queue)
    }
  }

If I try to execute it providing A as some sealed case class, then I got error on compile time:

Couldn't find sh.srv.docsp.services.core.FileHelper.A constructor.
Error while trying to generate zamblauskas.csv.parser.ColumnReads[sh.srv.docsp.services.core.FileHelper.A].
Either fix the error or provide zamblauskas.csv.parser.ColumnReads[sh.srv.docsp.services.core.FileHelper.A].

We can't use it for csv without column name?!

I like the simplicity of this lib, but there's no column name on my csv, so I'd like to use it without column name.
I solve the issue by adding the header in a string format in my code, but I think there should be a more elegant solution!

Integration with `Akka Streams`

Could be split into:

  • modularizing the code into core (domain/dsl/functional stuff) and backend (current parse whole string at once)
  • a new backend which would produce an Akka Flow

Issue with email

I have one CSV file that contains one column with email address.

I get the following error during parsing :

myCsv.csv:3:20 expected (Semis | &"}" | end-of-input)
xx;xx;[email protected];xxxx
                   ^

Is there one tip to enable to parse column with email address

No implicit support for Long

When trying to convert .csv data from a stream or file that has made it to a comma and new line delimited string into a case class used by an application, it would be good (in certain circumstances, essential) to have an expanded list of "native" Scala types. Presently, there is support for the following types:

String
Int
Float
Double
Boolean

I propose adding Long to this list and have created a Pull Request for this.

Why is this essential? When dealing with AWS S3 Objects, the document info needed to fully describe an entry includes a Long type for the content-length. The other types that might be considered important to support are BigDecimal and BigInt, but they are more involved since they do not have implicit converters in Scala's StringOps class. BigDecimal is used for money a lot in many projects including Squants, and it is also used extensively in default situations for Slick and Postgres. Big Int could come along for the ride. I will work on a Pull Request for the Bigs, but Long is terribly time sensitive, so if the Long pull request could be approved very soon, that would be most appreciated!

Column limit

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).

Unused import warning with Scala 2.11

Hi!

I've found that compiling with -Ywarn-unused-import produces really weird warning:

[warn] /home/limansky/projects/myproject/src/main/scala/org/mypackage/MyClass.scala:1:0: Unused import
[warn] package org.mypackage
[warn] ^

It looks like the issue reproduces only with Scala 2.11. I've googled little bit, it seems it related to macros, and play-json faced with same issue (they were able to solve it).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.