asdfgh19 commented on code in PR #3518:
URL: https://github.com/apache/calcite/pull/3518#discussion_r1393578254


##########
linq4j/src/test/java/org/apache/calcite/linq4j/test/InlinerTest.java:
##########
@@ -152,6 +154,31 @@ void checkAssignInConditionOptimizedOut(int modifiers, 
String s) {
     assertThat(Expressions.toString(builder.toBlock()), is(s));
   }
 
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6109";>[CALCITE-6109]
+   * OptimizeShuttle should not create new instances of TernaryExpression
+   * if it does not do any optimization</a>.
+   */
+  @Test void testInlineTernaryNonOptimized() {
+    Statement originStatement =
+        Expressions.return_(null,
+            Expressions.makeTernary(ExpressionType.Conditional,
+                Expressions.makeBinary(ExpressionType.NotEqual,
+                    Expressions.parameter(int.class, "a"),
+                    Expressions.constant(1)),
+                Expressions.parameter(int.class, "b"),
+                Expressions.parameter(int.class, "c")));
+    b.add(originStatement);
+    BlockStatement block = b.toBlock();
+    assertEquals(block.statements.size(), 1);
+    assertSame(originStatement, block.statements.get(0));

Review Comment:
   Because the Javadoc comment of the BlockBuilder#optimize method indicates 
that this method returns whether any optimizations were made, and the basis for 
its judgment is whether the original statement and the statement optimized by 
InlineVariableVisitor and OptimizeShuttle are the same instance.
   
   Moreover, in the Shuttle class, all visit methods will check the 
corresponding statement. If the fields of the statement have not been modified, 
the original statement will be returned.
   
   So I wrote this test case as simple as possible, which only includes one 
line of code that ensures the conventions of the BlockBuilder and Shuttle 
classes.



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