[ 
https://issues.apache.org/jira/browse/FLINK-6881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16054990#comment-16054990
 ] 

ASF GitHub Bot commented on FLINK-6881:
---------------------------------------

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

    https://github.com/apache/flink/pull/4144#discussion_r122852900
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/StreamTableEnvironment.scala
 ---
    @@ -437,39 +437,64 @@ abstract class StreamTableEnvironment(
         var rowtime: Option[(Int, String)] = None
         var proctime: Option[(Int, String)] = None
     
    -    exprs.zipWithIndex.foreach {
    -      case (RowtimeAttribute(reference@UnresolvedFieldReference(name)), 
idx) =>
    -        if (rowtime.isDefined) {
    +    def extractRowtime(idx: Int, name: String, origName: Option[String]): 
Unit = {
    +      if (rowtime.isDefined) {
    +        throw new TableException(
    +          "The rowtime attribute can only be defined once in a table 
schema.")
    +      } else {
    +        val mappedIdx = streamType match {
    +          case pti: PojoTypeInfo[_] =>
    +            pti.getFieldIndex(origName.getOrElse(name))
    --- End diff --
    
    When user write a mistake row-time property name of POJO. e.g.:
    `(recordTimeA as rowtime).rowtime` --> correct name is `recordTime`.
    will get the exception as follows:
    ```
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
        at 
org.apache.flink.table.api.StreamTableEnvironment.org$apache$flink$table$api$StreamTableEnvironment$$extractRowtime$1(StreamTableEnvironment.scala:453)
        at 
org.apache.flink.table.api.StreamTableEnvironment$$anonfun$validateAndExtractTimeAttributes$1.apply(StreamTableEnvironment.scala:484)
    ```
    I suggest that:
    1. May be we need check the row-time property name of POJO as early as 
possible. 
    2. We should check the index value must >= 0, If no so, we should throw a 
exception with clearly error information. 


> Creating a table from a POJO and defining a time attribute fails
> ----------------------------------------------------------------
>
>                 Key: FLINK-6881
>                 URL: https://issues.apache.org/jira/browse/FLINK-6881
>             Project: Flink
>          Issue Type: Bug
>          Components: Table API & SQL
>    Affects Versions: 1.3.0
>            Reporter: Timo Walther
>            Assignee: Timo Walther
>
> Creating a table from a DataStream of POJOs fails when the user tries to 
> define a rowtime attribute.
> There are multiple reasons in {{ExpressionParser}} as well as 
> {{StreamTableEnvironment#validateAndExtractTimeAttributes}}.
> See also: 
> https://stackoverflow.com/questions/44448022/apache-flink-1-3-table-api-rowtime-strange-behavior



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to