1717
1818package org .apache .spark .sql .catalyst .expressions
1919
20- import java .sql .Timestamp
2120import java .time .{DateTimeException , LocalDate , LocalDateTime , ZoneId }
2221import java .time .temporal .IsoFields
23- import java .util .{ Locale , TimeZone }
22+ import java .util .Locale
2423
2524import scala .util .control .NonFatal
2625
@@ -336,48 +335,6 @@ case class SecondWithFraction(child: Expression, timeZoneId: Option[String] = No
336335 }
337336}
338337
339- case class Milliseconds (child : Expression , timeZoneId : Option [String ] = None )
340- extends UnaryExpression with ImplicitCastInputTypes with TimeZoneAwareExpression {
341-
342- override def inputTypes : Seq [AbstractDataType ] = Seq (TimestampType )
343- // DecimalType is used here to not lose precision while converting microseconds to
344- // the fractional part of milliseconds. Scale 3 is taken to have all microseconds as
345- // the fraction. The precision 8 should cover 2 digits for seconds, 3 digits for
346- // milliseconds and 3 digits for microseconds.
347- override def dataType : DataType = DecimalType (8 , 3 )
348- override def withTimeZone (timeZoneId : String ): TimeZoneAwareExpression =
349- copy(timeZoneId = Option (timeZoneId))
350-
351- override protected def nullSafeEval (timestamp : Any ): Any = {
352- DateTimeUtils .getMilliseconds(timestamp.asInstanceOf [Long ], zoneId)
353- }
354-
355- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
356- val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
357- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
358- defineCodeGen(ctx, ev, c => s " $dtu.getMilliseconds( $c, $zid) " )
359- }
360- }
361-
362- case class Microseconds (child : Expression , timeZoneId : Option [String ] = None )
363- extends UnaryExpression with ImplicitCastInputTypes with TimeZoneAwareExpression {
364-
365- override def inputTypes : Seq [AbstractDataType ] = Seq (TimestampType )
366- override def dataType : DataType = IntegerType
367- override def withTimeZone (timeZoneId : String ): TimeZoneAwareExpression =
368- copy(timeZoneId = Option (timeZoneId))
369-
370- override protected def nullSafeEval (timestamp : Any ): Any = {
371- DateTimeUtils .getMicroseconds(timestamp.asInstanceOf [Long ], zoneId)
372- }
373-
374- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
375- val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
376- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
377- defineCodeGen(ctx, ev, c => s " $dtu.getMicroseconds( $c, $zid) " )
378- }
379- }
380-
381338@ ExpressionDescription (
382339 usage = " _FUNC_(date) - Returns the day of year of the date/timestamp." ,
383340 examples = """
@@ -2034,86 +1991,12 @@ case class MakeTimestamp(
20341991 override def prettyName : String = " make_timestamp"
20351992}
20361993
2037- case class Millennium (child : Expression ) extends UnaryExpression with ImplicitCastInputTypes {
2038-
2039- override def inputTypes : Seq [AbstractDataType ] = Seq (DateType )
2040-
2041- override def dataType : DataType = IntegerType
2042-
2043- override protected def nullSafeEval (date : Any ): Any = {
2044- DateTimeUtils .getMillennium(date.asInstanceOf [Int ])
2045- }
2046-
2047- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
2048- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
2049- defineCodeGen(ctx, ev, c => s " $dtu.getMillennium( $c) " )
2050- }
2051- }
2052-
2053- case class Century (child : Expression ) extends UnaryExpression with ImplicitCastInputTypes {
2054-
2055- override def inputTypes : Seq [AbstractDataType ] = Seq (DateType )
2056-
2057- override def dataType : DataType = IntegerType
2058-
2059- override protected def nullSafeEval (date : Any ): Any = {
2060- DateTimeUtils .getCentury(date.asInstanceOf [Int ])
2061- }
2062-
2063- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
2064- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
2065- defineCodeGen(ctx, ev, c => s " $dtu.getCentury( $c) " )
2066- }
2067- }
2068-
2069- case class Decade (child : Expression ) extends UnaryExpression with ImplicitCastInputTypes {
2070-
2071- override def inputTypes : Seq [AbstractDataType ] = Seq (DateType )
2072-
2073- override def dataType : DataType = IntegerType
2074-
2075- override protected def nullSafeEval (date : Any ): Any = {
2076- DateTimeUtils .getDecade(date.asInstanceOf [Int ])
2077- }
2078-
2079- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
2080- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
2081- defineCodeGen(ctx, ev, c => s " $dtu.getDecade( $c) " )
2082- }
2083- }
2084-
2085- case class Epoch (child : Expression , timeZoneId : Option [String ] = None )
2086- extends UnaryExpression with ImplicitCastInputTypes with TimeZoneAwareExpression {
2087-
2088- override def inputTypes : Seq [AbstractDataType ] = Seq (TimestampType )
2089- // DecimalType is used to not lose precision while converting microseconds to
2090- // the fractional part of seconds. Scale 6 is taken to have all microseconds as
2091- // the fraction. The precision 20 should cover whole valid range of years [1, 9999]
2092- // plus negative years that can be used in some cases though are not officially supported.
2093- override def dataType : DataType = DecimalType (20 , 6 )
2094- override def withTimeZone (timeZoneId : String ): TimeZoneAwareExpression =
2095- copy(timeZoneId = Option (timeZoneId))
2096-
2097- override protected def nullSafeEval (timestamp : Any ): Any = {
2098- DateTimeUtils .getEpoch(timestamp.asInstanceOf [Long ], zoneId)
2099- }
2100-
2101- override protected def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
2102- val dtu = DateTimeUtils .getClass.getName.stripSuffix(" $" )
2103- val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
2104- defineCodeGen(ctx, ev, c => s " $dtu.getEpoch( $c, $zid) " )
2105- }
2106- }
2107-
21081994object DatePart {
21091995
21101996 def parseExtractField (
21111997 extractField : String ,
21121998 source : Expression ,
21131999 errorHandleFunc : => Nothing ): Expression = extractField.toUpperCase(Locale .ROOT ) match {
2114- case " MILLENNIUM" | " MILLENNIA" | " MIL" | " MILS" => Millennium (source)
2115- case " CENTURY" | " CENTURIES" | " C" | " CENT" => Century (source)
2116- case " DECADE" | " DECADES" | " DEC" | " DECS" => Decade (source)
21172000 case " YEAR" | " Y" | " YEARS" | " YR" | " YRS" => Year (source)
21182001 case " ISOYEAR" => IsoYear (source)
21192002 case " QUARTER" | " QTR" => Quarter (source)
@@ -2127,11 +2010,6 @@ object DatePart {
21272010 case " HOUR" | " H" | " HOURS" | " HR" | " HRS" => Hour (source)
21282011 case " MINUTE" | " M" | " MIN" | " MINS" | " MINUTES" => Minute (source)
21292012 case " SECOND" | " S" | " SEC" | " SECONDS" | " SECS" => SecondWithFraction (source)
2130- case " MILLISECONDS" | " MSEC" | " MSECS" | " MILLISECON" | " MSECONDS" | " MS" =>
2131- Milliseconds (source)
2132- case " MICROSECONDS" | " USEC" | " USECS" | " USECONDS" | " MICROSECON" | " US" =>
2133- Microseconds (source)
2134- case " EPOCH" => Epoch (source)
21352013 case _ => errorHandleFunc
21362014 }
21372015}
0 commit comments