-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19758][SQL] Resolving timezone aware expressions with time zone when resolving inline table #17114
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
[SPARK-19758][SQL] Resolving timezone aware expressions with time zone when resolving inline table #17114
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -19,16 +19,16 @@ 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 | ||
| import org.apache.spark.sql.catalyst.{CatalystConf, InternalRow} | ||
| import org.apache.spark.sql.catalyst.expressions.{Cast, TimeZoneAwareExpression} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.types.{StructField, StructType} | ||
|
|
||
| /** | ||
| * An analyzer rule that replaces [[UnresolvedInlineTable]] with [[LocalRelation]]. | ||
| */ | ||
| object ResolveInlineTables extends Rule[LogicalPlan] { | ||
| case class ResolveInlineTables(conf: CatalystConf) extends Rule[LogicalPlan] { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = plan transformUp { | ||
| case table: UnresolvedInlineTable if table.expressionsResolved => | ||
| validateInputDimension(table) | ||
|
|
@@ -95,10 +95,14 @@ object ResolveInlineTables extends Rule[LogicalPlan] { | |
| InternalRow.fromSeq(row.zipWithIndex.map { case (e, ci) => | ||
| val targetType = fields(ci).dataType | ||
| try { | ||
| if (e.dataType.sameType(targetType)) { | ||
| e.eval() | ||
| val castedExpr = if (e.dataType.sameType(targetType)) { | ||
| e | ||
| } else { | ||
| Cast(e, targetType).eval() | ||
| Cast(e, targetType) | ||
| } | ||
| castedExpr match { | ||
| case te: TimeZoneAwareExpression => te.withTimeZone(conf.sessionLocalTimeZone).eval() | ||
|
||
| case _ => castedExpr.eval() | ||
| } | ||
| } catch { | ||
| case NonFatal(ex) => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,9 @@ select * from values ("one", array(0, 1)), ("two", array(2, 3)) as data(a, b); | |
| -- decimal and double coercion | ||
| select * from values ("one", 2.0), ("two", 3.0D) as data(a, b); | ||
|
|
||
| -- string to timestamp | ||
| select * from values timestamp('1991-12-06 00:00:00.0') as data(a); | ||
|
||
|
|
||
| -- error reporting: nondeterministic function rand | ||
| select * from values ("one", rand(5)), ("two", 3.0D) as data(a, b); | ||
|
|
||
|
|
||
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.
is it possible to fix this bug by re-order analyzer rules?
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.
I tried before. But the resolution rules will add new timezone-aware expressions, so it still needs the rule to resolve timezone-aware expressions after resolution rules.