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

    https://github.com/apache/spark/pull/21031#discussion_r180993164
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
 ---
    @@ -34,28 +76,38 @@ import org.apache.spark.sql.types._
           > SELECT _FUNC_(array('b', 'd', 'c', 'a'));
            4
       """)
    -case class Size(child: Expression) extends UnaryExpression with 
ExpectsInputTypes {
    +case class Size(child: Expression) extends SizeUtil {
       override def dataType: DataType = IntegerType
    -  override def inputTypes: Seq[AbstractDataType] = 
Seq(TypeCollection(ArrayType, MapType))
    -  override def nullable: Boolean = false
     
       override def eval(input: InternalRow): Any = {
    -    val value = child.eval(input)
    -    if (value == null) {
    -      -1
    -    } else child.dataType match {
    -      case _: ArrayType => value.asInstanceOf[ArrayData].numElements()
    -      case _: MapType => value.asInstanceOf[MapData].numElements()
    -    }
    +    sizeEval(child, input, false)
       }
     
       override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    -    val childGen = child.genCode(ctx)
    -    ev.copy(code = s"""
    -      boolean ${ev.isNull} = false;
    -      ${childGen.code}
    -      ${CodeGenerator.javaType(dataType)} ${ev.value} = ${childGen.isNull} 
? -1 :
    -        (${childGen.value}).numElements();""", isNull = FalseLiteral)
    +    doSizeGenCode(ctx, ev, false)
    +  }
    +}
    +
    +/**
    + * Given an array or map, returns its size as BigInt. Returns -1 if null.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(expr) - Returns the size of an array or a map as BigInt. 
Returns -1 if null.",
    --- End diff --
    
    I will update https://github.com/apache/spark/pull/21037, too



---

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

Reply via email to