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

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

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

    https://github.com/apache/flink/pull/3063#discussion_r95308316
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/logical/operators.scala
 ---
    @@ -92,20 +92,19 @@ case class Project(projectList: Seq[NamedExpression], 
child: LogicalNode) extend
       }
     
       override protected[logical] def construct(relBuilder: RelBuilder): 
RelBuilder = {
    -    val allAlias = projectList.forall(_.isInstanceOf[Alias])
         child.construct(relBuilder)
    -    if (allAlias) {
    -      // Calcite's RelBuilder does not translate identity projects even if 
they rename fields.
    -      //   Add a projection ourselves (will be automatically removed by 
translation rules).
    -      val project = LogicalProject.create(relBuilder.peek(),
    +    // Calcite's RelBuilder does not translate identity projects even if 
they rename fields.
    +    // We add a projection ourselves (will be automatically removed by 
translation rules).
    +    val project = LogicalProject.create(
    --- End diff --
    
    Good point !  The hack code existed because of Calcite's RelBuilder does 
not create  project when only rename fields.  The `project( Iterable<? extends 
RexNode> nodes, Iterable<String> fieldNames, boolean force)` was introduced and 
fixed this issue by Calcite-1342. 
    
    I have tried to replace the hack code by the following code, and all tests 
passed !
    
    ```scala
    override protected[logical] def construct(relBuilder: RelBuilder): 
RelBuilder = {
        child.construct(relBuilder)
        relBuilder.project(
          projectList.map {
            case Alias(c, _, _) => c.toRexNode(relBuilder)
            case n@_ => n.toRexNode(relBuilder)
          }.asJava,
          projectList.map(_.name).asJava,
          true)
    }
    ```
    
     


> WordCountTable fails
> --------------------
>
>                 Key: FLINK-5357
>                 URL: https://issues.apache.org/jira/browse/FLINK-5357
>             Project: Flink
>          Issue Type: Bug
>          Components: Table API & SQL
>            Reporter: Timo Walther
>            Assignee: Timo Walther
>
> The execution of org.apache.flink.table.examples.java.WordCountTable fails:
> {code}
> Exception in thread "main" org.apache.flink.table.api.TableException: POJO 
> does not define field name: TMP_0
>       at 
> org.apache.flink.table.typeutils.TypeConverter$$anonfun$2.apply(TypeConverter.scala:85)
>       at 
> org.apache.flink.table.typeutils.TypeConverter$$anonfun$2.apply(TypeConverter.scala:81)
>       at scala.collection.immutable.List.foreach(List.scala:318)
>       at 
> org.apache.flink.table.typeutils.TypeConverter$.determineReturnType(TypeConverter.scala:81)
>       at 
> org.apache.flink.table.plan.nodes.dataset.DataSetCalc.translateToPlan(DataSetCalc.scala:110)
>       at 
> org.apache.flink.table.api.BatchTableEnvironment.translate(BatchTableEnvironment.scala:305)
>       at 
> org.apache.flink.table.api.BatchTableEnvironment.translate(BatchTableEnvironment.scala:289)
>       at 
> org.apache.flink.table.api.java.BatchTableEnvironment.toDataSet(BatchTableEnvironment.scala:146)
>       at 
> org.apache.flink.table.examples.java.WordCountTable.main(WordCountTable.java:56)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:498)
>       at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
> {code} 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to