caicancai commented on code in PR #3839: URL: https://github.com/apache/calcite/pull/3839#discussion_r1667241861
########## core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java: ########## @@ -4202,67 +4205,55 @@ private static class LogicalNotImplementor extends AbstractRexCallImplementor { * appropriate base (i.e. base e for LN). */ private static class LogImplementor extends AbstractRexCallImplementor { - LogImplementor() { + private final SqlLibrary library; + LogImplementor(SqlLibrary library) { super("log", NullPolicy.STRICT, true); + this.library = library; } @Override Expression implementSafe(final RexToLixTranslator translator, final RexCall call, final List<Expression> argValueList) { - return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList)); - } - - private static List<Expression> args(RexCall call, - List<Expression> argValueList) { - Expression operand0 = argValueList.get(0); - final Expressions.FluentList<Expression> list = Expressions.list(operand0); - switch (call.getOperator().getName()) { - case "LOG": - if (argValueList.size() == 2) { - return list.append(argValueList.get(1)).append(Expressions.constant(0)); - } - // fall through - case "LN": - return list.append(Expressions.constant(Math.exp(1))).append(Expressions.constant(0)); - case "LOG10": - return list.append(Expressions.constant(BigDecimal.TEN)).append(Expressions.constant(0)); - default: - throw new AssertionError("Operator not found: " + call.getOperator()); + if (library == SqlLibrary.MYSQL) { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 1)); + } else if (library == SqlLibrary.POSTGRESQL) { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 2)); + } else { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 0)); } } - } - - /** Implementor for the {@code LN}, {@code LOG}, {@code LOG2} and {@code LOG10} operators - * on Mysql and Spark library - * - * <p>Handles all logarithm functions using log rules to determine the - * appropriate base (i.e. base e for LN). - */ - private static class LogMysqlImplementor extends AbstractRexCallImplementor { - LogMysqlImplementor() { - super("log", NullPolicy.STRICT, true); - } - - @Override Expression implementSafe(final RexToLixTranslator translator, - final RexCall call, final List<Expression> argValueList) { - return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList)); - } private static List<Expression> args(RexCall call, - List<Expression> argValueList) { - Expression operand0 = argValueList.get(0); + List<Expression> argValueList, int flag) { + Expression operand0; + Expression operand1; + if (flag == 0 && argValueList.size() == 2) { + operand0 = argValueList.get(0); + operand1 = argValueList.get(1); + } else if ((flag == 1 || flag == 2) && argValueList.size() == 2) { Review Comment: Thank you for your code. I will optimize this part based on your code. Thank you very much. ########## core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java: ########## @@ -4202,67 +4205,55 @@ private static class LogicalNotImplementor extends AbstractRexCallImplementor { * appropriate base (i.e. base e for LN). */ private static class LogImplementor extends AbstractRexCallImplementor { - LogImplementor() { + private final SqlLibrary library; + LogImplementor(SqlLibrary library) { super("log", NullPolicy.STRICT, true); + this.library = library; } @Override Expression implementSafe(final RexToLixTranslator translator, final RexCall call, final List<Expression> argValueList) { - return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList)); - } - - private static List<Expression> args(RexCall call, - List<Expression> argValueList) { - Expression operand0 = argValueList.get(0); - final Expressions.FluentList<Expression> list = Expressions.list(operand0); - switch (call.getOperator().getName()) { - case "LOG": - if (argValueList.size() == 2) { - return list.append(argValueList.get(1)).append(Expressions.constant(0)); - } - // fall through - case "LN": - return list.append(Expressions.constant(Math.exp(1))).append(Expressions.constant(0)); - case "LOG10": - return list.append(Expressions.constant(BigDecimal.TEN)).append(Expressions.constant(0)); - default: - throw new AssertionError("Operator not found: " + call.getOperator()); + if (library == SqlLibrary.MYSQL) { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 1)); + } else if (library == SqlLibrary.POSTGRESQL) { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 2)); + } else { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList, 0)); } } - } - - /** Implementor for the {@code LN}, {@code LOG}, {@code LOG2} and {@code LOG10} operators - * on Mysql and Spark library - * - * <p>Handles all logarithm functions using log rules to determine the - * appropriate base (i.e. base e for LN). - */ - private static class LogMysqlImplementor extends AbstractRexCallImplementor { - LogMysqlImplementor() { - super("log", NullPolicy.STRICT, true); - } - - @Override Expression implementSafe(final RexToLixTranslator translator, - final RexCall call, final List<Expression> argValueList) { - return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList)); - } private static List<Expression> args(RexCall call, - List<Expression> argValueList) { - Expression operand0 = argValueList.get(0); + List<Expression> argValueList, int flag) { + Expression operand0; + Expression operand1; + if (flag == 0 && argValueList.size() == 2) { + operand0 = argValueList.get(0); + operand1 = argValueList.get(1); + } else if ((flag == 1 || flag == 2) && argValueList.size() == 2) { Review Comment: Thank you so much -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org