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

    https://github.com/apache/flink/pull/1958#discussion_r62852367
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/expressions/cast.scala
 ---
    @@ -20,19 +20,55 @@ package org.apache.flink.api.table.expressions
     import org.apache.calcite.rex.RexNode
     import org.apache.calcite.tools.RelBuilder
     
    -import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
    +import org.apache.flink.api.common.typeinfo.{NumericTypeInfo, 
TypeInformation}
     import org.apache.flink.api.table.typeutils.TypeConverter
    +import org.apache.flink.api.table.validate._
     
    -case class Cast(child: Expression, tpe: TypeInformation[_]) extends 
UnaryExpression {
    +case class Cast(child: Expression, resultType: TypeInformation[_]) extends 
UnaryExpression {
     
    -  override def toString = s"$child.cast($tpe)"
    +  override def toString = s"$child.cast($resultType)"
     
       override def toRexNode(implicit relBuilder: RelBuilder): RexNode = {
    -    relBuilder.cast(child.toRexNode, TypeConverter.typeInfoToSqlType(tpe))
    +    relBuilder.cast(child.toRexNode, 
TypeConverter.typeInfoToSqlType(resultType))
       }
     
    -  override def makeCopy(anyRefs: Seq[AnyRef]): this.type = {
    +  override def makeCopy(anyRefs: Array[AnyRef]): this.type = {
         val child: Expression = anyRefs.head.asInstanceOf[Expression]
    -    copy(child, tpe).asInstanceOf[this.type]
    +    copy(child, resultType).asInstanceOf[this.type]
    +  }
    +
    +  override def validateInput(): ExprValidationResult = {
    +    if (Cast.canCast(child.resultType, resultType)) {
    +      ValidationSuccess
    +    } else {
    +      ValidationFailure(s"Unsupported cast from ${child.resultType} to 
$resultType")
    +    }
    +  }
    +}
    +
    +object Cast {
    --- End diff --
    
    I would also move this into `typeutils`. We'll may need it somewhere else 
too.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to