YiwenWu commented on code in PR #3839:
URL: https://github.com/apache/calcite/pull/3839#discussion_r1666739823
##########
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:
A way for reference:
```
private static class LogImplementor extends AbstractRexCallImplementor {
@Override Expression implementSafe(final RexToLixTranslator translator,
final RexCall call, final List<Expression> argValueList) {
return Expressions.call(BuiltInMethod.LOG.method, args(call,
argValueList, library));
}
private static List<Expression> args(RexCall call,
List<Expression> argValueList, SqlLibrary library) {
Pair<Expression, Expression> baseAndValuePair;
if (argValueList.size() == 1) {
ConstantExpression defaultBase = library == SqlLibrary.POSTGRESQL
? Expressions.constant(BigDecimal.TEN) :
Expressions.constant(Math.exp(1));
baseAndValuePair = Pair.of(defaultBase, argValueList.get(0));
} else {
boolean isBaseFirst = library == SqlLibrary.MYSQL || library ==
SqlLibrary.POSTGRESQL;
baseAndValuePair = isBaseFirst ? Pair.of(argValueList.get(0),
argValueList.get(1))
: Pair.of(argValueList.get(1), argValueList.get(0));
}
Expression base = baseAndValuePair.left;
Expression value = baseAndValuePair.right;
final Expressions.FluentList<Expression> list = Expressions.list();
switch (call.getOperator().getName()) {
case "LOG":
return list.append(value).append(base);
case "LN":
return list.append(value).append(Expressions.constant(Math.exp(1)));
case "LOG2":
return list.append(value).append(Expressions.constant(2));
case "LOG10":
return
list.append(value).append(Expressions.constant(BigDecimal.TEN));
default:
throw new AssertionError("Operator not found: " +
call.getOperator());
}
}
}
```
--
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]