spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8641][SQL] Native Spark Window function...
Date Wed, 09 Dec 2015 00:21:31 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9819#discussion_r47035952
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala
---
    @@ -328,3 +281,222 @@ object FrameBoundaryExtractor {
         case _ => None
       }
     }
    +
    +/**
    + * A window function is a function that can only be evaluated in the context of a window
operator.
    + */
    +trait WindowFunction extends Expression {
    +  /** Frame in which the window operator must be executed. */
    +  def frame: WindowFrame = UnspecifiedFrame
    +}
    +
    +abstract class OffsetWindowFunction
    +  extends Expression with WindowFunction with Unevaluable with ImplicitCastInputTypes
{
    +  val input: Expression
    +  val default: Expression
    +  val offset: Expression
    +  val offsetSign: Int
    +
    +  override def children: Seq[Expression] = Seq(input, offset, default)
    +
    +  override def foldable: Boolean = input.foldable && (default == null || default.foldable)
    +
    +  override def nullable: Boolean = input.nullable && (default == null || default.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")
    +    }
    +    val boundary = ValueFollowing(offsetSign * offsetValue)
    +    SpecifiedWindowFrame(RowFrame, boundary, boundary)
    +  }
    +
    +  override def dataType: DataType = input.dataType
    +
    +  override def inputTypes: Seq[AbstractDataType] =
    +    Seq(AnyDataType, IntegerType, TypeCollection(input.dataType, NullType))
    +
    +  override def toString: String = s"$prettyName($input, $offset, $default)"
    +}
    +
    +case class Lead(input: Expression, offset: Expression, default: Expression)
    +  extends OffsetWindowFunction {
    +
    +  def this(input: Expression, offset: Expression) =
    +    this(input, offset, Literal(null))
    +
    +  def this(input: Expression) =
    +    this(input, Literal(1), Literal(null))
    +
    +  def this() = this(Literal(null), Literal(1), Literal(null))
    --- End diff --
    
    Just curious why not `def this() = this(Literal(null))`?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message