Github user jiangxb1987 commented on a diff in the pull request:
https://github.com/apache/spark/pull/18540#discussion_r130217171
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala
---
@@ -351,20 +356,25 @@ abstract class OffsetWindowFunction
override def nullable: Boolean = default == null || default.nullable ||
input.nullable
- override lazy val frame = {
- // This will be triggered by the Analyzer.
- val offsetValue = offset.eval() match {
- case o: Int => o
- case x => throw new AnalysisException(
- s"Offset expression must be a foldable integer expression: $x")
- }
+ override lazy val frame: WindowFrame = {
val boundary = direction match {
- case Ascending => ValueFollowing(offsetValue)
- case Descending => ValuePreceding(offsetValue)
+ case Ascending => offset
+ case Descending => UnaryMinus(offset)
}
SpecifiedWindowFrame(RowFrame, boundary, boundary)
}
+ override def checkInputDataTypes(): TypeCheckResult = {
+ val check = super.checkInputDataTypes()
+ if (check.isFailure) {
+ check
+ } else if (!offset.foldable) {
+ TypeCheckFailure(s"Offset expression '$offset' must be a literal.")
--- End diff --
Currently it's only used by lead()/lag() functions, that both checked the
input types, so we're not able to test this from sql.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]