Skip to content

Commit

Permalink
fix Date serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies Liu committed Apr 9, 2015
1 parent 59266d1 commit da64742
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/pkg/R/deserialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ readType <- function(con) {
}

readDate <- function(con) {
as.Date(readInt(con), origin = "1970-01-01")
as.Date(readString(con))
}

readTime <- function(con) {
Expand Down
2 changes: 1 addition & 1 deletion R/pkg/R/serialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ writeEnv <- function(con, env) {
}

writeDate <- function(con, date) {
writeInt(con, as.integer(date))
writeString(con, as.character(date))
}

writeTime <- function(con, time) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala/org/apache/spark/api/r/SerDe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ private[spark] object SerDe {
}

def readDate(in: DataInputStream): Date = {
val d = in.readInt()
new Date(d.toLong * 24 * 3600 * 1000)
Date.valueOf(readString(in))
}

def readTime(in: DataInputStream): Time = {
Expand Down Expand Up @@ -277,7 +276,7 @@ private[spark] object SerDe {
}

def writeDate(out: DataOutputStream, value: Date): Unit = {
out.writeInt((value.getTime / 1000 / 3600 / 24).toInt)
writeString(out, value.toString)
}

def writeTime(out: DataOutputStream, value: Time): Unit = {
Expand Down

0 comments on commit da64742

Please sign in to comment.