Giter VIP home page Giter VIP logo

itto-csv's People

Contributors

gekomad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

itto-csv's Issues

Upgrade to Scala 2.13.1

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

Generic Type to CSV

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

Error parsing LocalDate

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

toCsvL

	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]

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.