gekomad / itto-csv Goto Github PK
View Code? Open in Web Editor NEWItto-CSV is a pure scala library for working with the CSV format
License: Apache License 2.0
Itto-CSV is a pure scala library for working with the CSV format
License: Apache License 2.0
I tried to open a PR for this but got stuck on a sbt-pgp download error. This error also occurs if I clone and sbt build
with no changes.
[error] (coursierResolutions) coursier.error.ResolutionError$CantDownloadModule: Error downloading com.jsuereth:sbt-pgp;sbtVersion=1.0;scalaVersion=2.12:2.0.0
[error] Not found
[error] not found: ~/.ivy2/local/com.jsuereth/sbt-pgp/scala_2.12/sbt_1.0/2.0.0/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/jsuereth/sbt-pgp_2.12_1.0/2.0.0/sbt-pgp-2.0.0.pom
[error] download error: Caught javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target (sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target) while downloading https://repo.typesafe.com/typesafe/ivy-releases/com.jsuereth/sbt-pgp/scala_2.12/sbt_1.0/2.0.0/ivys/ivy.xml
Is it possible to convert generic objects into CSV String.
implicit val report: CsvStringEncoder[A] =
new CsvStringEncoder[A] {
override def encode(value: A): String = value match {
case report1: Report1 => ???
case report2: Report2 => ???
case _ => throw new IllegalArgumentException
}
}
val stream = publisher.toStream[IO].map(hit => toCsv(hit.to[A]))
where Report1 and Report2 are normal case classes
I'm having an issue trying to parse a java.time.LocalDate
from a file, but the strange thing is that I was able to parse java.time.LocalDatetime
fine.
This compiles
import java.time.LocalDateTime
import cats.data.NonEmptyList
import com.github.gekomad.ittocsv.core.ParseFailure
import com.github.gekomad.ittocsv.parser.IttoCSVFormat
import com.github.gekomad.ittocsv.core.FromCsv._
case class CustomerId(value: String)
case class Customer(id: CustomerId, date: LocalDateTime)
object FileParser {
implicit val csvFormat = IttoCSVFormat.default
implicit def csvFieldToId: String => Either[ParseFailure, CustomerId] = (s => Right(CustomerId(s)))
implicit def csvFieldToLocalDateTime: String => Either[ParseFailure, LocalDateTime] = {
s =>
scala.util.Try {
Right(LocalDateTime.parse(s.trim))
}.getOrElse(Left(ParseFailure(s"Could not convert '$s' to LocalDate")))
}
def parseFile(file: String): List[Either[NonEmptyList[ParseFailure], Customer]] = {
val fileWithoutHeader = file.split("\n").drop(1).toList
fromCsv[Customer](fileWithoutHeader).toList
}
}
But this (which is the code above but with LocalDateTime
replaced with LocalDate
everywhere) does not compile
import java.time.LocalDate
import cats.data.NonEmptyList
import com.github.gekomad.ittocsv.core.ParseFailure
import com.github.gekomad.ittocsv.parser.IttoCSVFormat
import com.github.gekomad.ittocsv.core.FromCsv._
case class CustomerId(value: String)
case class Customer(id: CustomerId, date: LocalDate)
object FileParser {
implicit val csvFormat = IttoCSVFormat.default
implicit def csvFieldToId: String => Either[ParseFailure, CustomerId] = (s => Right(CustomerId(s)))
implicit def csvFieldToLocalDate: String => Either[ParseFailure, LocalDate] = {
s =>
scala.util.Try {
Right(LocalDate.parse(s.trim))
}.getOrElse(Left(ParseFailure(s"Could not convert '$s' to LocalDate")))
}
def parseFile(file: String): List[Either[NonEmptyList[ParseFailure], Customer]] = {
val fileWithoutHeader = file.split("\n").drop(1).toList
fromCsv[Customer](fileWithoutHeader).toList
}
}
Trying to compile the one with LocalDate
gives the error below, which as far as I know means that I haven't provided an implicit to parse one of the fields in my case class, but I've provided a parser for both.
[error] could not find implicit value for evidence parameter of type com.github.gekomad.ittocsv.core.Schema[entities.Customer]
[error] fromCsv[Customer](fileWithoutHeader).toList
Should I be able to parse any random class? I'm using v1.1.0
Can you please cross build with Scala.js? https://github.com/scala-js/scala-js/releases/tag/v1.0.1
import com.github.gekomad.ittocsv.core.ToCsv._
implicit val csvFormat = com.github.gekomad.ittocsv.parser.IttoCSVFormat.default.withPrintHeader(true)
val testBean = ParquetStruct(120000000,120000000,123213,43532,123,12,3123,231,123123,312312,1,"hello",1200000000,"101","10101")
val csvBeans: Seq[SinoiovParquetStruct] = testBean::Nil
val csvStr = toCsvL(csvBeans) //error
println(csvStr)
ERROR information :
No implicits found for parameter evidence$2:Header.fieldNames[ParquetStruct]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.