fhueske commented on code in PR #30222: URL: https://github.com/apache/flink/pull/30222#discussion_r4798801454
########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/utils/NestedProjectionUtilFilterTest.java: ########## @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.planner.plan.utils; + +import org.apache.flink.table.planner.calcite.FlinkRexBuilder; +import org.apache.flink.table.planner.calcite.FlinkTypeFactory; +import org.apache.flink.table.planner.calcite.FlinkTypeSystem; + +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.StructKind; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.calcite.sql.type.SqlTypeName; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for {@link NestedProjectionUtil#rewriteForFilter}. */ +class NestedProjectionUtilFilterTest { + + private final FlinkTypeFactory typeFactory = + new FlinkTypeFactory( + Thread.currentThread().getContextClassLoader(), FlinkTypeSystem.INSTANCE); + private final RexBuilder rexBuilder = new FlinkRexBuilder(typeFactory); + + @Test + void testLeavesInInputOrderAndUnusedColumnsPassThrough() { + // Structs are referenced out of their column order. The unused leaves s.c and t.x are + // dropped. The unused struct u passes through whole, pruning it is left to + // ProjectFilterTransposeRule. + final RelDataType input = + inputRow( + "id", intType(), + "s", row("a", intType(), "b", intType(), "c", intType()), + "k", intType(), + "t", row("x", intType(), "y", intType()), + "u", row("p", intType(), "q", intType())); + + final FilterNestedProjectionResult result = + rewrite( + List.of(access(input, 3, "y"), access(input, 1, "b"), ref(input, 0)), + greaterThan(access(input, 1, "a"), ref(input, 2)), + input); + + assertThat(strings(result.inputProjects())) + .containsExactly("$0", "$1.b", "$1.a", "$2", "$3.y", "$4"); + assertThat(strings(result.rewrittenProjects())).containsExactly("$4", "$1", "$0"); + assertThat(result.rewrittenCondition()).hasToString(">($2, $3)"); + } Review Comment: I'd prefer to keep it. `rewriteForFilter` is a utility, and its unit tests check the rewritten expressions and their types directly and cheaply, in isolation. The rule's behavior is covered by the plan tests in `ProjectNestedFieldFilterTransposeRuleTest`, and `NestedProjectionPushDownTest` covers it with the production optimizer. There is some overlap in the test cases because the "common" cases are tested in this unit test and the plan tests, but some more special cases are only tested here. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
