Github user maropu commented on a diff in the pull request:
https://github.com/apache/spark/pull/21240#discussion_r186662955
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/generators.scala
---
@@ -222,6 +222,54 @@ case class Stack(children: Seq[Expression]) extends
Generator {
}
}
+/**
+ * Replicate the row N times. N is specified as the first argument to the
function.
+ * {{{
+ * SELECT replicate_rows(2, "val1", "val2") ->
+ * 2 val1 val2
+ * 2 val1 val2
+ * }}}
+ */
+@ExpressionDescription(
+usage = "_FUNC_(n, expr1, ..., exprk) - Replicates `n`, `expr1`, ...,
`exprk` into `n` rows.",
+examples = """
+ Examples:
+ > SELECT _FUNC_(2, "val1", "val2");
+ 2 val1 val2
+ 2 val1 val2
+ """)
+case class ReplicateRows(children: Seq[Expression]) extends Generator with
CodegenFallback {
+ private lazy val numColumns = children.length
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ if (numColumns < 2) {
+ TypeCheckResult.TypeCheckFailure(s"$prettyName requires at least 2
arguments.")
+ } else if (children.head.dataType != LongType) {
+ TypeCheckResult.TypeCheckFailure("The number of rows must be a
positive long value.")
--- End diff --
How about this message? `The first argument type must be byte, short, int,
or long, but ${children.head.dataType} found.` BTW, it seems we don't reject
negative values? (The current message says the number must be positive
though...?)
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]