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)
}
```
---
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 [email protected] or file a JIRA ticket
with INFRA.
---