Github user kiszk commented on a diff in the pull request:
https://github.com/apache/spark/pull/21024#discussion_r180784794
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
@@ -287,3 +287,70 @@ case class ArrayContains(left: Expression, right:
Expression)
override def prettyName: String = "array_contains"
}
+
+
+/**
+ * Returns the maximum value in the array.
+ */
+@ExpressionDescription(
+ usage = "_FUNC_(array) - Returns the maximum value in the array.",
+ examples = """
+ Examples:
+ > SELECT _FUNC_(array(1, 20, null, 3));
+ 20
+ """, since = "2.4.0")
+case class ArrayMax(child: Expression) extends UnaryExpression with
ImplicitCastInputTypes {
+
+ override def nullable: Boolean =
+ child.nullable || child.dataType.asInstanceOf[ArrayType].containsNull
+
+ override def foldable: Boolean = child.foldable
+
+ override def inputTypes: Seq[AbstractDataType] = Seq(ArrayType)
+
+ private lazy val ordering = TypeUtils.getInterpretedOrdering(dataType)
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ val typeCheckResult = super.checkInputDataTypes()
+ if (typeCheckResult.isSuccess) {
+ TypeUtils.checkForOrderingExpr(dataType, s"function $prettyName")
+ } else {
+ typeCheckResult
+ }
+ }
+
+ override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
+ val childGen = child.genCode(ctx)
+ val javaType = CodeGenerator.javaType(dataType)
+ val i = ctx.freshName("i")
+ val item = ExprCode("",
+ isNull = StatementValue(s"${childGen.value}.isNullAt($i)",
"boolean"),
+ value = StatementValue(CodeGenerator.getValue(childGen.value,
dataType, i), javaType))
+ ev.copy(code =
+ s"""
+ |${childGen.code}
+ |boolean ${ev.isNull} = true;
+ |$javaType ${ev.value} = ${CodeGenerator.defaultValue(dataType)};
--- End diff --
nvm, `isNull` is used for assigning the initial value.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]