-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29074][SQL] Optimize date_format for foldable fmt
#25782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
de8dafb
5ab324f
85a290e
ee2a7d2
3292acc
3b5a8c2
0242852
a9fd8e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -589,22 +589,43 @@ case class DateFormatClass(left: Expression, right: Expression, timeZoneId: Opti | |
|
|
||
| override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, StringType) | ||
|
|
||
| override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression = | ||
| var formatter: Option[TimestampFormatter] = None | ||
|
|
||
| override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression = { | ||
| if (formatter.isEmpty && right.foldable) { | ||
| val format = right.eval().toString | ||
HyukjinKwon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| formatter = Some(TimestampFormatter( | ||
| format, | ||
| DateTimeUtils.getZoneId(timeZoneId), | ||
| Locale.US)) | ||
MaxGekk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| copy(timeZoneId = Option(timeZoneId)) | ||
| } | ||
|
|
||
| override protected def nullSafeEval(timestamp: Any, format: Any): Any = { | ||
| val df = TimestampFormatter(format.toString, zoneId) | ||
| UTF8String.fromString(df.format(timestamp.asInstanceOf[Long])) | ||
| val tf = if (formatter.isEmpty) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| TimestampFormatter(format.toString, zoneId, Locale.US) | ||
MaxGekk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| formatter.get | ||
| } | ||
| UTF8String.fromString(tf.format(timestamp.asInstanceOf[Long])) | ||
| } | ||
|
|
||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| val tf = TimestampFormatter.getClass.getName.stripSuffix("$") | ||
| val zid = ctx.addReferenceObj("zoneId", zoneId, classOf[ZoneId].getName) | ||
| val locale = ctx.addReferenceObj("locale", Locale.US) | ||
| defineCodeGen(ctx, ev, (timestamp, format) => { | ||
| s"""UTF8String.fromString($tf$$.MODULE$$.apply($format.toString(), $zid, $locale) | ||
| formatter.map { tf => | ||
| val timestampFormatter = ctx.addReferenceObj("timestampFormatter", tf) | ||
MaxGekk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| defineCodeGen(ctx, ev, (timestamp, _) => { | ||
| s"""UTF8String.fromString($timestampFormatter.format($timestamp))""" | ||
| }) | ||
| }.getOrElse { | ||
| val tf = TimestampFormatter.getClass.getName.stripSuffix("$") | ||
| val zid = ctx.addReferenceObj("zoneId", zoneId, classOf[ZoneId].getName) | ||
| val locale = ctx.addReferenceObj("locale", Locale.US) | ||
| defineCodeGen(ctx, ev, (timestamp, format) => { | ||
| s"""UTF8String.fromString($tf$$.MODULE$$.apply($format.toString(), $zid, $locale) | ||
| .format($timestamp))""" | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| override def prettyName: String = "date_format" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.