51zero / 51zero/eel-sdk

CsvSource type conversion with custom schema

Đang mở
#370 3 bình luận 0 reaction 1 người được giao Được @grewalr nhận Xem trên GitHub
Ngôn ngữ chính
Scala
Star
147
Fork
32
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

From the project README - [CSV source part](https://github.com/51zero/eel-sdk#csv-source) I got the idea that type conversion for loaded CSV should be performed according to the specified schema.

But if I define a custom schema for a `CsvSource` which has columns with other types than `String` (`Int` for example), then the values in that column are still returned as `String`.

Is it intended behaviour, bug or it just haven't been implemented?

Runnable example:

```scala
import java.io.ByteArrayInputStream
import java.nio.charset.StandardCharsets
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

val stream = new ByteArrayInputStream(exampleCsvString.getBytes(StandardCharsets.UTF_8))
val schema = new StructType(Vector(
Field("A", IntType.Signed),
Field("B", DoubleType),
Field("C", IntType.Signed),
Field("D", StringType)
))
val ds = new CsvSource(stream _, Some(schema)).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
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Look at the CsvSource implementation in the eel-sdk codebase, likely under io.eels.component.csv. Examine how the schema is applied during row parsing. The test case provided shows that values are returned as Strings despite Int/Double schema. Start by running the provided example to confirm the issue, then trace the data flow from CSV parsing to row creation. Check if type conversion logic exists or needs to be added. Verify by writing a test in the project's test suite.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
scala
Lĩnh vực
data-engineering
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.