typelevel / typelevel/frameless

Support java.sql.Date and java.sql.Timestamp so they work just as in plain Spark datasets.

Open
#205 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Scala
Stars
895
Forks
135
Avg merge
1d 16h
Merged PRs (30d)
3

Description

Given the following snippet:

    import frameless._
    import org.apache.spark.sql.catalyst.util.DateTimeUtils

    implicit val dateAsInt: Injection[java.sql.Date, Int] = Injection(DateTimeUtils.fromJavaDate, DateTimeUtils.toJavaDate)

    // create some df (typically read from an orc or parquet file)
    val today = new java.sql.Date(System.currentTimeMillis)
    val df = Seq((42, today)).toDF("i", "d")

    // and turn it into a TypedDataset
    case class P(i: Int, d: java.sql.Date)
    val ds = df.as[P]
    val tds = TypedDataset.create(ds)

in plain Dataset you can use:

ds.filter(ds("d") === today).show 

+---+----------+
|  i|         d|
+---+----------+
| 42|2017-11-10|
+---+----------+

but in TypedDataset this results in an AnalysisException

tds.filter(tds('d) === today).show().run
org.apache.spark.sql.AnalysisException: cannot resolve '(`d` = FramelessLit(2017-11-10))' due to data type mismatch: differing types in '(`d` = FramelessLit(2017-11-10))' (date and int).;;
'Filter (d#82 = FramelessLit(2017-11-10))
+- Project [_1#78 AS i#81, _2#79 AS d#82]
   +- LocalRelation [_1#78, _2#79]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported TypedDataset filter failure with java.sql.Date, then inspect how TypedDataset handles literals and type conversions. Check the corresponding handling for java.sql.Timestamp as well. Done means both types can be compared in TypedDataset expressions like their plain Spark Dataset equivalents without a date/int mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, scala, spark
Domain
data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.