Github user xccui commented on a diff in the pull request:
https://github.com/apache/flink/pull/4846#discussion_r145650965
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkCalciteSqlValidator.scala
---
@@ -48,4 +49,19 @@ class FlinkCalciteSqlValidator(
insert: SqlInsert): RelDataType = {
typeFactory.asInstanceOf[JavaTypeFactory].toSql(targetRowType)
}
+
+ override def validateJoin(join: SqlJoin, scope: SqlValidatorScope): Unit
= {
+ // Due to the improperly translation of lateral table left outer join
(see CALCITE-2004), we
+ // need to temporarily forbid the common predicates until the problem
is fixed.
+ // The check for join with a lateral table is actually quite tricky.
+ if (join.getJoinType == JoinType.LEFT &&
+ join.getRight.toString.startsWith("TABLE(")) { // TABLE
(`func`(`foo`)) AS...
--- End diff --
Yes, checking the string here may not be reliable and we need to search for
the node whose kind is `SqlKind.COLLECTION_TABLE`.
However, the recursive check could fail with subqueries. For instance,
given the following query,
```
SELECT *
FROM MyTable2 LEFT OUTER JOIN
(SELECT c, s
FROM MyTable LEFT OUTER JOIN LATERAL TABLE(func1(c)) AS T(s) on true)
ON c2 = s
```
the lateral table in the subquery will be detected by the out join. Thus I
think we should check the collection table, which should always be covered by
an `AS` node, directly, i.e.,
```
private def isCollectionTable(node: SqlNode): Boolean = {
node match {
case n: SqlCall if n.getKind == SqlKind.AS =>
n.getOperandList.get(0).getKind == SqlKind.COLLECTION_TABLE
}
}
```
What do you think?
---