-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20329][SQL] Make timezone aware expression without timezone unresolved #17641
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
0654409
ceec2b0
b5848ca
88be49e
cc8de3d
d7bc1e8
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 |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.analysis | |
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.{Cast, TimeZoneAwareExpression} | ||
| import org.apache.spark.sql.catalyst.expressions.Cast | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
@@ -99,12 +99,9 @@ case class ResolveInlineTables(conf: SQLConf) extends Rule[LogicalPlan] { | |
| val castedExpr = if (e.dataType.sameType(targetType)) { | ||
| e | ||
| } else { | ||
| Cast(e, targetType) | ||
| Cast(e, targetType, Some(conf.sessionLocalTimeZone)) | ||
|
||
| } | ||
| castedExpr.transform { | ||
| case e: TimeZoneAwareExpression if e.timeZoneId.isEmpty => | ||
| e.withTimeZone(conf.sessionLocalTimeZone) | ||
| }.eval() | ||
| castedExpr.eval() | ||
|
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. If there are nested expressions which are timezone aware, I think we still need to attach time zone to them?
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. I guess now that
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. oh, right. I saw the changes to |
||
| } catch { | ||
| case NonFatal(ex) => | ||
| table.failAnalysis(s"failed to evaluate expression ${e.sql}: ${ex.getMessage}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ import java.util.{Calendar, TimeZone} | |
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.analysis.TypeCheckResult | ||
| import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, CodegenFallback, ExprCode} | ||
| import org.apache.spark.sql.catalyst.util.DateTimeUtils | ||
| import org.apache.spark.sql.types._ | ||
|
|
@@ -34,6 +33,9 @@ import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String} | |
| * Common base class for time zone aware expressions. | ||
| */ | ||
| trait TimeZoneAwareExpression extends Expression { | ||
| /** The expression is only resolved when the time zone has been set. */ | ||
| override lazy val resolved: Boolean = | ||
| childrenResolved && checkInputDataTypes().isSuccess && timeZoneId.isDefined | ||
|
Contributor
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. The implementation may have some custom resolution logic, how about
Contributor
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. I tried doing this. Scala does not allow you to call |
||
|
|
||
| /** the timezone ID to be used to evaluate value. */ | ||
| def timeZoneId: Option[String] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResolveInlineTablescan beCastSupportand we should usecastof it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done