flink-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jark Wu <j...@apache.org>
Subject Re: Question about type cast in ExpressionReducer's reduce procedure
Date Thu, 29 Jun 2017 06:37:47 GMT
Hi Aegeaner,

First of all, the ExpressionReducer actually restores the origin return
type after reducing, see
https://github.com/apache/flink/blob/master/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/ExpressionReducer.scala#L122

So the reduced result and type should be correct. Did you find the wrong
return type?

The `RexBuilder.makeLiteral(Object value, RelDataType type, boolean
allowCast)` accepts any values and will cast Integer back to Date
internally.

Regards,
Jark Wu


2017-06-29 12:38 GMT+08:00 郭健 <guo.jian@immomo.com>:

> Hi all,
>             I am implementing a STR_TO_DATE scalar SQL function to flink,
> and found return type casted from java.sql.Date to Integer in Flink’s
> ExpressionReducer:
> https://github.com/apache/flink/blob/master/flink-
> libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/
> ExpressionReducer.scala#L56
>
> // we need to cast here for RexBuilder.makeLiteral
>
>
>       case (SqlTypeName.DATE, e) =>
>
>
>         Some(
>
>
>           rexBuilder.makeCast(typeFactory.createTypeFromTypeInfo(BasicTypeInfo.INT_TYPE_INFO),
> e)
>
>
>         )
>
>
>
>             so str_to_date('01,5,2013','%d,%m,%Y')" must return an
> Integer, which conflicted with my implementation.
>
>             My question is: why should we do this? I have seen in comments
> the reason to do this here is: “we need to cast here for
> RexBuilder.makeLiteral”, But is it reasonale to change user function’s
> return Type? Should we restore the origin return type after the reduce?
>
>
> Thanks,
> Aegeaner
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message