ParseToTimestamp Expression¶
ParseToTimestamp
is a RuntimeReplaceable expression that represents the following standard functions in logical query plans:
Creating Instance¶
ParseToTimestamp
takes the following to be created:
- Left Expression
- Optional Format Expression
- DataType
- Optional TimeZone ID (default: unspecified)
-
failOnError
flag
ParseToTimestamp
is created when:
ParseToTimestampLTZExpressionBuilder
is requested tobuild
(forto_timestamp_ltz
standard function)ParseToTimestampNTZExpressionBuilder
is requested tobuild
(forto_timestamp_ntz
standard function)TryToTimestampExpressionBuilder
is requested tobuild
(fortry_to_timestamp
standard function)- to_timestamp standard function is used
nodeName¶
nodeName
is the following text:
to_timestamp
Replacement Expression¶
RuntimeReplaceable
replacement: Expression
replacement
is part of the RuntimeReplaceable abstraction.
With the format specified, replacement
is a GetTimestamp(left, f, dataType, timeZoneId)
expression.
Otherwise, replacement
is a Cast(left, dataType, timeZoneId)
expression.
Demo¶
// DEMO to_timestamp(s: Column): Column
import java.sql.Timestamp
import java.time.LocalDateTime
val times = Seq(Timestamp.valueOf(LocalDateTime.of(2018, 5, 30, 0, 0, 0)).toString).toDF("time")
scala> times.printSchema
root
|-- time: string (nullable = true)
import org.apache.spark.sql.functions.to_timestamp
val q = times.select(to_timestamp($"time") as "ts")
scala> q.printSchema
root
|-- ts: timestamp (nullable = true)
val plan = q.queryExecution.analyzed
scala> println(plan.numberedTreeString)
00 Project [to_timestamp('time, None) AS ts#29]
01 +- Project [value#16 AS time#18]
02 +- LocalRelation [value#16]
import org.apache.spark.sql.catalyst.expressions.ParseToTimestamp
val ptt = plan.expressions.head.children.head.asInstanceOf[ParseToTimestamp]
scala> println(ptt.numberedTreeString)
00 to_timestamp('time, None)
01 +- cast(time#18 as timestamp)
02 +- time#18: string