You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by xuanyuanking <gi...@git.apache.org> on 2018/10/26 15:09:06 UTC

[GitHub] spark pull request #21348: [SPARK-22739][Catalyst] Additional Expression Sup...

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

    https://github.com/apache/spark/pull/21348#discussion_r228563440
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala ---
    @@ -1799,3 +1805,65 @@ case class ValidateExternalType(child: Expression, expected: DataType)
         ev.copy(code = code, isNull = input.isNull)
       }
     }
    +
    +/**
    + * Determines if the given value is an instanceof a given class.
    + *
    + * @param value the value to check
    + * @param checkedType the class to check the value against
    + */
    +case class InstanceOf(
    +    value: Expression,
    +    checkedType: Class[_]) extends Expression with NonSQLExpression {
    +
    +  override def nullable: Boolean = false
    +  override def children: Seq[Expression] = value :: Nil
    +  override def dataType: DataType = BooleanType
    +
    +  override def eval(input: InternalRow): Any =
    +    throw new UnsupportedOperationException("Only code-generated evaluation is supported.")
    +
    +  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    +
    +    val obj = value.genCode(ctx)
    +
    +    val code =
    +      s"""
    +        ${obj.code}
    +        final boolean ${ev.value} = ${obj.value} instanceof ${checkedType.getName};
    +      """
    +
    +    ev.copy(code = code, isNull = FalseLiteral)
    +  }
    +}
    +
    +/**
    + * Casts the result of an expression to another type.
    + *
    + * @param value The value to cast
    + * @param resultType The type to which the value should be cast
    + */
    +case class ObjectCast(value: Expression, resultType: DataType)
    +  extends Expression with NonSQLExpression {
    +
    +  override def nullable: Boolean = value.nullable
    +  override def dataType: DataType = resultType
    +  override def children: Seq[Expression] = value :: Nil
    +
    +  override def eval(input: InternalRow): Any =
    +    throw new UnsupportedOperationException("Only code-generated evaluation is supported.")
    --- End diff --
    
    Any problem on implementing none code-generated evaluation?


---

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