Github user ueshin commented on a diff in the pull request: https://github.com/apache/spark/pull/21069#discussion_r185716705 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala --- @@ -883,3 +883,70 @@ case class Concat(children: Seq[Expression]) extends Expression { override def sql: String = s"concat(${children.map(_.sql).mkString(", ")})" } + +/** + * Remove all elements that equal to element from the given array + */ +@ExpressionDescription( + usage = "_FUNC_(array, element) - Remove all elements that equal to element from array.", + examples = """ + Examples: + > SELECT _FUNC_(array(1, 2, 3, null, 3), 3); + [1,2,null] + """, since = "2.4.0") +case class ArrayRemove(left: Expression, right: Expression) + extends BinaryExpression with ImplicitCastInputTypes with CodegenFallback { + + override def dataType: DataType = left.dataType + + override def inputTypes: Seq[AbstractDataType] = + Seq(ArrayType, left.dataType.asInstanceOf[ArrayType].elementType) + + override def nullSafeEval(arr: Any, value: Any): Any = { + val elementType = left.dataType.asInstanceOf[ArrayType].elementType + val data = arr.asInstanceOf[ArrayData].toArray[AnyRef](elementType).filter(_ != value) + new GenericArrayData(data.asInstanceOf[Array[Any]]) + } + + override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { + val elementType = left.dataType.asInstanceOf[ArrayType].elementType + nullSafeCodeGen(ctx, ev, (arr, value) => { + val arrayClass = classOf[GenericArrayData].getName + val values = ctx.freshName("values") + val i = ctx.freshName("i") + val pos = ctx.freshName("arrayPosition") + val numsToRemove = ctx.freshName("newArrLen") + val getValue = CodeGenerator.getValue(arr, right.dataType, i) --- End diff -- `CodeGenerator.getValue(arr, elementType, i)`?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org