mihaibudiu commented on code in PR #4318:
URL: https://github.com/apache/calcite/pull/4318#discussion_r2049964408


##########
core/src/main/java/org/apache/calcite/sql/SqlCall.java:
##########
@@ -116,16 +116,21 @@ public int operandCount() {
         getOperandList());
   }
 
+  private boolean isParenthesesRequired(SqlWriter writer, int leftPrec, int 
rightPrec) {

Review Comment:
   I would rename this function to "needsParentheses".



##########
core/src/main/java/org/apache/calcite/sql/SqlCall.java:
##########
@@ -116,16 +116,21 @@ public int operandCount() {
         getOperandList());
   }
 
+  private boolean isParenthesesRequired(SqlWriter writer, int leftPrec, int 
rightPrec) {
+    final SqlOperator operator = getOperator();
+    boolean condition = leftPrec > operator.getLeftPrec()
+        || (operator.getRightPrec() <= rightPrec && (rightPrec != 0))
+        || writer.isAlwaysUseParentheses() && isA(SqlKind.EXPRESSION)
+        || (operator.getRightPrec() <= rightPrec + 1 && 
isA(SqlKind.COMPARISON));
+    return condition && !(getKind() == SqlKind.SET_SEMANTICS_TABLE);

Review Comment:
   It looks that this condition is easier to write starting with this test:
   `if (getKind() == SET_SEMANTICS_TABLE) return false;`
   Then followed by the original expression



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