Airblader commented on a change in pull request #16984: URL: https://github.com/apache/flink/pull/16984#discussion_r695735863
########## File path: flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/rules/logical/PushProjectIntoTableSourceScanRuleTest.java ########## @@ -243,4 +270,153 @@ public void testProjectFieldAccessWithITEM() { + "`outer_map`['item'] " + "FROM ItemTable"); } + + @Test + public void testMetadataProjectionWithoutProjectionPushDownWhenSupported() { + createMetadataTableWithoutProjectionPushDown("T1", true); + + util().verifyRelPlan("SELECT m1, metadata FROM T1"); + assertThat( + MetadataNoProjectionPushDownTableFactory.appliedMetadataKeys.get(), + contains("m1", "m2")); + } + + @Test + public void testMetadataProjectionWithoutProjectionPushDownWhenNotSupported() { + createMetadataTableWithoutProjectionPushDown("T2", false); + + util().verifyRelPlan("SELECT m1, metadata FROM T2"); + assertThat( + MetadataNoProjectionPushDownTableFactory.appliedMetadataKeys.get(), + contains("m1", "m2", "m3")); + } + + @Test + public void testMetadataProjectionWithoutProjectionPushDownWhenSupportedAndNoneSelected() { + createMetadataTableWithoutProjectionPushDown("T3", true); + + util().verifyRelPlan("SELECT 1 FROM T3"); + assertThat(MetadataNoProjectionPushDownTableFactory.appliedMetadataKeys.get(), hasSize(0)); + } + + @Test + public void testMetadataProjectionWithoutProjectionPushDownWhenNotSupportedAndNoneSelected() { + createMetadataTableWithoutProjectionPushDown("T4", false); + + util().verifyRelPlan("SELECT 1 FROM T4"); + assertThat( + MetadataNoProjectionPushDownTableFactory.appliedMetadataKeys.get(), + contains("m1", "m2", "m3")); + } + + // --------------------------------------------------------------------------------------------- + + private void createMetadataTableWithoutProjectionPushDown( + String name, boolean supportsMetadataProjection) { + util().tableEnv() + .createTable( + name, + TableDescriptor.forConnector( + MetadataNoProjectionPushDownTableFactory.IDENTIFIER) + .schema( + Schema.newBuilder() + .columnByMetadata("m1", STRING()) + .columnByMetadata("metadata", STRING(), "m2") + .columnByMetadata("m3", STRING()) + .build()) + .option(SUPPORTS_METADATA_PROJECTION, supportsMetadataProjection) + .build()); + } + + // --------------------------------------------------------------------------------------------- + + /** Factory for {@link Source}. */ + public static class MetadataNoProjectionPushDownTableFactory Review comment: (No such source exists in `TestValuesFactory`, and the structure there is already monstrous enough for me to not want to add another source into it. For testing purposes it would be quite nice if abilities could be disabled at runtime rather than be defined purely by implementation of an interface, I guess, but a bit late for that now) -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org