LakeShen commented on code in PR #3436:
URL: https://github.com/apache/calcite/pull/3436#discussion_r1334906120


##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -3119,6 +3125,96 @@ void testInnerJoinValues(String format) {
             "deptno=10; name=Sales; employees=[{100, 10, Bill, 10000.0, 1000}, 
{150, 10, Sebastian, 7000.0, null}]; location={-122, 38}");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5984";>[CALCITE-5984]</a>
+   * Disabling trimming of unused fields via config and program. */
+  @Test void testJoinWithTrimmingDisabled() {
+    CalciteAssert.hr().query("select \"d\".\"name\" from \"hr\".\"depts\" as 
\"d\" \n"
+                + "  join \"hr\".\"emps\" as \"e\" on \"d\".\"deptno\" = 
\"e\".\"deptno\" \n")
+        .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+            (Consumer<Holder<Config>>) configHolder ->
+            configHolder.set(configHolder.get().withTrimUnusedFields(false)))
+        .withHook(Hook.PROGRAM,
+            (Consumer<Holder<Program>>)
+            programHolder -> programHolder
+                    .set(sequence(Programs.SUB_QUERY_PROGRAM, getProgram(), 
Programs.CALC_PROGRAM)))
+        .convertContains(""
+                + "LogicalProject(name=[$1])\n"
+                + "  LogicalJoin(condition=[=($0, $5)], joinType=[inner])\n"
+                + "    LogicalTableScan(table=[[hr, depts]])\n"
+                + "    LogicalTableScan(table=[[hr, emps]])\n"
+                + "");
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5984";>[CALCITE-5984]</a>
+   * Disabling trimming of unused fields via config and program. */
+  @Test void testJoinWithTrimmingEnabledByConfig() {
+    CalciteAssert.hr().query("select \"d\".\"name\" from \"hr\".\"depts\" as 
\"d\" \n"
+                + "  join \"hr\".\"emps\" as \"e\" on \"d\".\"deptno\" = 
\"e\".\"deptno\" \n")
+        .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+            (Consumer<Holder<Config>>) configHolder ->
+            configHolder.set(configHolder.get().withTrimUnusedFields(true)))
+        .withHook(Hook.PROGRAM,
+            (Consumer<Holder<Program>>)
+            programHolder -> programHolder
+                    .set(sequence(Programs.SUB_QUERY_PROGRAM, getProgram(), 
Programs.CALC_PROGRAM)))
+        .convertContains(""
+                + "LogicalProject(name=[$1])\n"
+                + "  LogicalJoin(condition=[=($0, $2)], joinType=[inner])\n"
+                + "    LogicalProject(deptno=[$0], name=[$1])\n"
+                + "      LogicalTableScan(table=[[hr, depts]])\n"
+                + "    LogicalProject(deptno=[$1])\n"
+                + "      LogicalTableScan(table=[[hr, emps]])\n"
+                + "");
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5984";>[CALCITE-5984]</a>
+   * Disabling trimming of unused fields via config and program. */
+  @Test void testJoinWithTrimmingEnabledByProgram() {
+    CalciteAssert.hr().query("select \"d\".\"name\" from \"hr\".\"depts\" as 
\"d\" \n"
+                + "  join \"hr\".\"emps\" as \"e\" on \"d\".\"deptno\" = 
\"e\".\"deptno\" \n")
+        .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+            (Consumer<Holder<Config>>) configHolder ->
+            configHolder.set(configHolder.get().withTrimUnusedFields(false)))
+        .withHook(Hook.PROGRAM,
+            (Consumer<Holder<Program>>)
+            programHolder -> programHolder
+                    .set(Programs.standard()))
+        .convertContains(""
+                + "LogicalProject(name=[$1])\n"
+                + "  LogicalJoin(condition=[=($0, $2)], joinType=[inner])\n"
+                + "    LogicalProject(deptno=[$0], name=[$1])\n"
+                + "      LogicalTableScan(table=[[hr, depts]])\n"
+                + "    LogicalProject(deptno=[$1])\n"
+                + "      LogicalTableScan(table=[[hr, emps]])\n"
+                + "");
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5984";>[CALCITE-5984]</a>
+   * Disabling trimming of unused fields via config and program. */
+  @Test void testJoinWithTrimmingEnabledByProgramAndConfig() {
+    CalciteAssert.hr().query("select \"d\".\"name\" from \"hr\".\"depts\" as 
\"d\" \n"
+                + "  join \"hr\".\"emps\" as \"e\" on \"d\".\"deptno\" = 
\"e\".\"deptno\" \n")
+        .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+            (Consumer<Holder<Config>>) configHolder ->
+                
configHolder.set(configHolder.get().withTrimUnusedFields(true)))

Review Comment:
   Hi @WegdanGhazi ,thanks for your reply.
   
   I have saw the difference between 
`testJoinWithTrimmingEnabledByProgramAndConfig` and 
`testJoinWithTrimmingEnabledByProgram`  is the withTrimUnusedFields param 
value,one is false,another is true.
   
   But the input sql and expected plan is same,so I'm a little confused about 
the purpose of these two unit tests.I thought a few code comments illustrating 
this case would make it easier for others to understand.



-- 
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]

Reply via email to