Github user ueshin commented on a diff in the pull request: https://github.com/apache/spark/pull/21208#discussion_r186356981 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala --- @@ -1229,3 +1229,140 @@ case class Flatten(child: Expression) extends UnaryExpression { override def prettyName: String = "flatten" } + +/** + * Returns the array containing the given input value (left) count (right) times. + */ +@ExpressionDescription( + usage = "_FUNC_(element, count) - Returns the array containing element count times.", + examples = """ + Examples: + > SELECT _FUNC_('123', 2); + ['123', '123'] + """) +case class ArrayRepeat(left: Expression, right: Expression) + extends BinaryExpression with ExpectsInputTypes { + + override def dataType: ArrayType = ArrayType(left.dataType, left.nullable) + + override def inputTypes: Seq[AbstractDataType] = Seq(AnyDataType, IntegerType) + + override def nullable: Boolean = right.nullable + + override def eval(input: InternalRow): Any = { + val count = right.eval(input) + if (count == null) { + null + } else { + new GenericArrayData(List.fill(count.asInstanceOf[Int])(left.eval(input))) + } + } + + override def prettyName: String = "array_repeat" + + override def nullSafeCodeGen(ctx: CodegenContext, --- End diff -- Yes, overriding `nullSafeCodeGen` is not suitable for this usage. So I think it would be good to put all code in `doGenCode`, or to create another method instead of overriding `nullSafeCodeGen`.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org