JiajunBernoulli commented on code in PR #3649:
URL: https://github.com/apache/calcite/pull/3649#discussion_r1467609436
##########
core/src/main/java/org/apache/calcite/sql/dialect/SnowflakeSqlDialect.java:
##########
@@ -42,34 +47,20 @@ public SnowflakeSqlDialect(Context context) {
@Override public void unparseCall(final SqlWriter writer, final SqlCall
call, final int leftPrec,
final int rightPrec) {
- switch (call.getKind()) {
- case BIT_AND:
- SqlCall bitAndCall = SqlLibraryOperators.BITAND_AGG
- .createCall(SqlParserPos.ZERO, call.getOperandList());
- super.unparseCall(writer, bitAndCall, leftPrec, rightPrec);
- break;
- case BIT_OR:
- SqlCall bitOrCall = SqlLibraryOperators.BITOR_AGG
- .createCall(SqlParserPos.ZERO, call.getOperandList());
- super.unparseCall(writer, bitOrCall, leftPrec, rightPrec);
- break;
- case CHAR_LENGTH:
- SqlCall lengthCall = SqlLibraryOperators.LENGTH
- .createCall(SqlParserPos.ZERO, call.getOperandList());
- super.unparseCall(writer, lengthCall, leftPrec, rightPrec);
- break;
- case ENDS_WITH:
- SqlCall endsWithCall = SqlLibraryOperators.ENDSWITH
- .createCall(SqlParserPos.ZERO, call.getOperandList());
- super.unparseCall(writer, endsWithCall, leftPrec, rightPrec);
- break;
- case STARTS_WITH:
- SqlCall startsWithCall = SqlLibraryOperators.STARTSWITH
- .createCall(SqlParserPos.ZERO, call.getOperandList());
- super.unparseCall(writer, startsWithCall, leftPrec, rightPrec);
- break;
- default:
- super.unparseCall(writer, call, leftPrec, rightPrec);
+ final HashMap<SqlKind, SqlOperator> map = new HashMap<>();
+ map.put(SqlKind.BIT_AND, SqlLibraryOperators.BITAND_AGG);
+ map.put(SqlKind.BIT_OR, SqlLibraryOperators.BITOR_AGG);
+ map.put(SqlKind.CHAR_LENGTH, SqlLibraryOperators.LENGTH);
+ map.put(SqlKind.ENDS_WITH, SqlLibraryOperators.ENDSWITH);
+ map.put(SqlKind.STARTS_WITH, SqlLibraryOperators.STARTSWITH);
+ map.put(SqlKind.MAX, SqlStdOperatorTable.MAX);
+ map.put(SqlKind.MIN, SqlStdOperatorTable.MIN);
+ SqlOperator op = map.get(call.getKind());
+ if (op != null) {
+ SqlCall newCall = op.createCall(SqlParserPos.ZERO,
call.getOperandList());
Review Comment:
1. Check-style failed.
2. We can use `final`
3. Do you like static field? It is free for you.
- We will build map when every unparse. If we have static map, this is
only one.
- The static field will also continue to occupy memory.
--
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]