godfreyhe commented on a change in pull request #15493:
URL: https://github.com/apache/flink/pull/15493#discussion_r609667236
##########
File path:
flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/plan/rules/logical/PushProjectIntoTableSourceScanRuleTest.java
##########
@@ -168,4 +197,22 @@ public void testNestProjectWithUpsertSource() {
util().verifyRelPlan(sqlQuery);
}
+
+ @Test
+ public void testNestedProjectFieldAccessWithITEM() {
+ util().verifyRelPlan(
+ "SELECT "
+ + "`Result`.data_arr[ID].`value`, "
+ + "`Result`.data_map['item'].`value`"
+ + "FROM NestedItemTable");
+ }
+
+ @Test
+ public void testProjectFieldAccessWithITEM() {
+ util().verifyRelPlan(
+ "SELECT "
+ + "`Result`.data_arr[ID].`value`, "
Review comment:
add a case about the array index is constant and a case about the second
level is same (the second level fields will be retained)
##########
File path:
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/utils/NestedProjectionUtil.scala
##########
@@ -269,18 +277,29 @@ private class NestedSchemaRewriter(schema: NestedSchema,
builder: RexBuilder) ex
private class NestedSchemaExtractor(schema: NestedSchema) extends
RexVisitorImpl[Unit](true) {
override def visitFieldAccess(fieldAccess: RexFieldAccess): Unit = {
- def internalVisit(fieldAccess: RexFieldAccess): (Int, List[String]) = {
+ def internalVisit(fieldAccess: RexFieldAccess): (Boolean, Int,
List[String]) = {
fieldAccess.getReferenceExpr match {
case ref: RexInputRef =>
- (ref.getIndex, List(ref.getName, fieldAccess.getField.getName))
+ (true, ref.getIndex, List(ref.getName, fieldAccess.getField.getName))
case fac: RexFieldAccess =>
- val (i, n) = internalVisit(fac)
- (i, n :+ fieldAccess.getField.getName)
+ val (success, i, n) = internalVisit(fac)
+ if (success) {
+ (success, i, n :+ fieldAccess.getField.getName)
+ } else {
+ (success, i, n)
+ }
Review comment:
return null if success is false
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]