Skip to content
Closed
Prev Previous commit
Next Next commit
Moved the only remaining function from DataTypeConversions to DateUtils
  • Loading branch information
vlyubin committed Apr 8, 2015
commit c327bc97469e0f90c0d9a5e0fdd8b44a32ff221f
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.plans.logical
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.{CatalystTypeConverters, analysis}
import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.types.{DataTypeConversions, StructType, StructField}
import org.apache.spark.sql.types.{StructType, StructField}

object LocalRelation {
def apply(output: Attribute*): LocalRelation = new LocalRelation(output)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.types

import java.sql.Date
import java.text.SimpleDateFormat
import java.util.{Calendar, TimeZone}

import org.apache.spark.sql.catalyst.expressions.Cast
Expand Down Expand Up @@ -57,4 +58,32 @@ object DateUtils {
}

def toString(days: Int): String = Cast.threadLocalDateFormat.get.format(toJavaDate(days))

def stringToTime(s: String): java.util.Date = {
if (!s.contains('T')) {
// JDBC escape string
if (s.contains(' ')) {
java.sql.Timestamp.valueOf(s)
} else {
java.sql.Date.valueOf(s)
}
} else if (s.endsWith("Z")) {
// this is zero timezone of ISO8601
stringToTime(s.substring(0, s.length - 1) + "GMT-00:00")
} else if (s.indexOf("GMT") == -1) {
// timezone with ISO8601
val inset = "+00.00".length
val s0 = s.substring(0, s.length - inset)
val s1 = s.substring(s.length - inset, s.length)
if (s0.substring(s0.lastIndexOf(':')).contains('.')) {
stringToTime(s0 + "GMT" + s1)
} else {
stringToTime(s0 + ".0GMT" + s1)
}
} else {
// ISO8601 with GMT insert
val ISO8601GMT: SimpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSz" )
ISO8601GMT.parse(s)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private[sql] object JsonRDD extends Logging {
value match {
// only support string as date
case value: java.lang.String =>
DateUtils.millisToDays(DataTypeConversions.stringToTime(value).getTime)
DateUtils.millisToDays(DateUtils.stringToTime(value).getTime)
case value: java.sql.Date => DateUtils.fromJavaDate(value)
}
}
Expand All @@ -400,7 +400,7 @@ private[sql] object JsonRDD extends Logging {
value match {
case value: java.lang.Integer => new Timestamp(value.asInstanceOf[Int].toLong)
case value: java.lang.Long => new Timestamp(value)
case value: java.lang.String => toTimestamp(DataTypeConversions.stringToTime(value).getTime)
case value: java.lang.String => toTimestamp(DateUtils.stringToTime(value).getTime)
}
}

Expand Down