You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by ueshin <gi...@git.apache.org> on 2018/06/07 21:31:49 UTC

[GitHub] spark pull request #21155: [SPARK-23927][SQL] Add "sequence" expression

Github user ueshin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21155#discussion_r193895158
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala ---
    @@ -1468,3 +1472,388 @@ case class Flatten(child: Expression) extends UnaryExpression {
     
       override def prettyName: String = "flatten"
     }
    +
    +@ExpressionDescription(
    +  usage = """
    +    _FUNC_(start, stop, step) - Generates an array of elements from start to stop (inclusive),
    +      incrementing by step. The type of the returned elements is the same as the type of argument
    +      expressions.
    +
    +      Supported types are: byte, short, integer, long, date, timestamp.
    +
    +      The start and stop expressions must resolve to the same type.
    +      If start and stop expressions resolve to the 'date' or 'timestamp' type
    +      then the step expression must resolve to the 'interval' type, otherwise to the same type
    +      as the start and stop expressions.
    +  """,
    +  arguments = """
    +    Arguments:
    +      * start - an expression. The start of the range.
    +      * stop - an expression. The end the range (inclusive).
    +      * step - an optional expression. The step of the range.
    +          By default step is 1 if start is less than or equal to stop, otherwise -1.
    +          For the temporal sequences it's 1 day and -1 day respectively.
    +          If start is greater than stop then the step must be negative, and vice versa.
    +  """,
    +  examples = """
    +    Examples:
    +      > SELECT _FUNC_(1, 5);
    +       [1, 2, 3, 4, 5]
    +      > SELECT _FUNC_(5, 1);
    +       [5, 4, 3, 2, 1]
    +      > SELECT _FUNC_(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);
    +       [2018-01-01, 2018-02-01, 2018-03-01]
    +  """,
    +  since = "2.4.0"
    +)
    +case class Sequence(
    +    start: Expression,
    +    stop: Expression,
    +    stepOpt: Option[Expression],
    +    timeZoneId: Option[String] = None)
    +  extends Expression
    +  with ExpectsInputTypes
    +  with TimeZoneAwareExpression {
    +
    +  import Sequence._
    +
    +  def this(start: Expression, stop: Expression) =
    +    this(start, stop, None, None)
    +
    +  def this(start: Expression, stop: Expression, step: Expression) =
    +    this(start, stop, Some(step), None)
    +
    +  override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
    +    copy(timeZoneId = Some(timeZoneId))
    +
    +  override def children: Seq[Expression] = Seq(start, stop) ++ stepOpt
    +
    +  override def foldable: Boolean = children.forall(_.foldable)
    +
    +  override def nullable: Boolean = children.exists(_.nullable)
    +
    +  override lazy val dataType: ArrayType = ArrayType(start.dataType, containsNull = false)
    +
    +  override def inputTypes: Seq[AbstractDataType] = {
    +    val elemType = dataType.elementType
    +    Seq(elemType, elemType) ++
    +      stepOpt.map(_ => elemType match {
    +        case DateType | TimestampType => CalendarIntervalType
    +        case _: IntegralType => elemType
    --- End diff --
    
    I'm wondering what was wrong with `checkInputDataTypes`, but I can't see the difference because the commit was just overwritten.


---

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