Git Product home page Git Product logo

Comments (3)

hannesmiller avatar hannesmiller commented on September 27, 2024

@flexik Have you considered using the SchemaInferrer?

val inferrer = SchemaInferrer(SchemaType.String, SchemaRule("qty", SchemaType.Int, false), SchemaRule(".*_id", SchemaType.Int))
CsvSource("myfile").withSchemaInferrer(inferrer)

I take your point though that perhaps if you explicitly pass in the schema it should use the schema under-the-hold - we will be looking into this.

from eel-sdk.

tszolar avatar tszolar commented on September 27, 2024

@hannesmiller Using SchemaInferrer yields the exactly same result as using schema directly. No type conversion happens. All Row fields are still Strings.

Updated example with SchemaInferrer:

import java.io.ByteArrayInputStream
import java.nio.charset.StandardCharsets

import io.eels.{DataTypeRule, SchemaInferrer}
import io.eels.component.csv.CsvSource
import io.eels.schema._

object CsvSourceTypeConversionTest extends App {

  val exampleCsvString =
    """A,B,C,D
      |1,2.2,3,foo
      |4,5.5,6,bar
    """.stripMargin

  def stream = new ByteArrayInputStream(exampleCsvString.getBytes(StandardCharsets.UTF_8))
  val inferrer = SchemaInferrer(
    StringType,
    DataTypeRule("A", IntType.Signed),
    DataTypeRule("B", DoubleType),
    DataTypeRule("C", IntType.Signed),
    DataTypeRule("D", StringType)
  )
  val ds = new CsvSource(stream _).withSchemaInferrer(inferrer).toDataStream()
  val firstRow = ds.iterator.toIterable.head
  val firstRowA = firstRow.get("A")
  println(firstRowA) // prints 1 as expected
  println(firstRowA.getClass.getTypeName) // prints java.lang.String
  assert(firstRowA == 1) // this assertion will fail because firstRowA is not an Int
}

from eel-sdk.

hannesmiller avatar hannesmiller commented on September 27, 2024

@flexik ok this maybe a bug that was introduced between versions - nevertheless I agree this should match the supplied schema - we will make this a priority for the next release which is looking like the early part of March.

Will keep you posted If we manage to get this resolved in alpha release beforehand.

Regards
Hannes

from eel-sdk.

Related Issues (20)

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.