-
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.spark.sql.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{Cast, Expression, ListQuery, TimeZoneAwareExpression} | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.DataType | ||
|
|
||
| /** | ||
| * Replace [[TimeZoneAwareExpression]] without timezone id by its copy with session local | ||
| * time zone. | ||
| */ | ||
| case class ResolveTimeZone(conf: SQLConf) extends Rule[LogicalPlan] { | ||
| private val transformTimeZoneExprs: PartialFunction[Expression, Expression] = { | ||
| case e: TimeZoneAwareExpression if e.timeZoneId.isEmpty => | ||
| e.withTimeZone(conf.sessionLocalTimeZone) | ||
| // Casts could be added in the subquery plan through the rule TypeCoercion while coercing | ||
| // the types between the value expression and list query expression of IN expression. | ||
| // We need to subject the subquery plan through ResolveTimeZone again to setup timezone | ||
| // information for time zone aware expressions. | ||
| case e: ListQuery => e.withNewPlan(apply(e.plan)) | ||
| } | ||
|
|
||
| override def apply(plan: LogicalPlan): LogicalPlan = | ||
| plan.resolveExpressions(transformTimeZoneExprs) | ||
|
|
||
| def resolveTimeZones(e: Expression): Expression = e.transform(transformTimeZoneExprs) | ||
| } | ||
|
|
||
| /** | ||
| * Mix-in trait for constructing valid [[Cast]] expressions. | ||
| */ | ||
| trait CastSupport { | ||
| /** | ||
| * Configuration used to create a valid cast expression. | ||
| */ | ||
| def conf: SQLConf | ||
|
|
||
| /** | ||
| * Create a Cast expression with the session local time zone. | ||
| */ | ||
| def cast(child: Expression, dataType: DataType): Cast = { | ||
| Cast(child, dataType, Option(conf.sessionLocalTimeZone)) | ||
| } | ||
| } |
| 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] | ||
|
|
||
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.
If there are nested expressions which are timezone aware, I think we still need to attach time zone to them?
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.
I guess now that
TimeZoneAwareExpressionis resolved if it hastimeZoneId, so we don't need to transform children.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.
oh, right. I saw the changes to
TimeZoneAwareExpression. :-)