Vladsz83 commented on code in PR #11478: URL: https://github.com/apache/ignite/pull/11478#discussion_r1725222730
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexImpTable.java: ########## @@ -2205,76 +2220,86 @@ private static class LogicalNotImplementor extends AbstractRexCallImplementor { } } - /** - * Implementation that calls a given {@link Method}. + /** Implementor for the {@code LN}, {@code LOG}, and {@code LOG10} operators. * - * <p>When method is not static, a new instance of the required class is - * created. + * <p>Handles all logarithm functions using log rules to determine the + * appropriate base (i.e. base e for LN). */ - private static class ReflectiveImplementor extends AbstractRexCallImplementor { - /** */ - protected final Method method; - + private static class LogImplementor extends AbstractRexCallImplementor { /** */ - ReflectiveImplementor(Method method, NullPolicy nullPolicy) { - super("reflective_" + method.getName(), nullPolicy, false); - this.method = method; + LogImplementor() { + super("log", NullPolicy.STRICT, true); } /** {@inheritDoc} */ - @Override Expression implementSafe(RexToLixTranslator translator, - RexCall call, List<Expression> argValueList) { - List<Expression> argValList0 = ConverterUtils.fromInternal(method.getParameterTypes(), argValueList); - if ((method.getModifiers() & Modifier.STATIC) != 0) - return Expressions.call(method, argValList0); + @Override Expression implementSafe(final RexToLixTranslator translator, + final RexCall call, final List<Expression> argValueList) { + return Expressions.call(BuiltInMethod.LOG.method, args(call, argValueList)); + } - // The UDF class must have a public zero-args constructor. - // Assume that the validator checked already. - final Expression target = Expressions.new_(method.getDeclaringClass()); - return Expressions.call(target, method, argValList0); + /** */ + 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)); + // fall through + case "LN": + return list.append(Expressions.constant(Math.exp(1))); + case "LOG10": + return list.append(Expressions.constant(BigDecimal.TEN)); + default: + throw new AssertionError("Operator not found: " + call.getOperator()); + } } } - /** Implementor for the {@code RAND} function. */ - private static class RandImplementor extends AbstractRexCallImplementor { + /** + * Implementation that a {@link java.lang.reflect.Method}. + * + * <p>If there are several methods in the list, calls the first that has the + * right number of arguments. + * + * <p>When method is not static, a new instance of the required class is + * created. + */ + private static class ReflectiveImplementor extends AbstractRexCallImplementor { /** */ - private final AbstractRexCallImplementor[] implementors = { - new ReflectiveImplementor(BuiltInMethod.RAND.method, nullPolicy), - new ReflectiveImplementor(BuiltInMethod.RAND_SEED.method, nullPolicy) - }; + protected final ImmutableList<? extends Method> methods; /** */ - RandImplementor() { - super("rand", NullPolicy.STRICT, false); + ReflectiveImplementor(List<? extends Method> methods) { + super("reflective_" + methods.get(0).getName(), NullPolicy.STRICT, false); + this.methods = ImmutableList.copyOf(methods); } /** {@inheritDoc} */ - @Override Expression implementSafe(final RexToLixTranslator translator, - final RexCall call, final List<Expression> argValueList) { - return implementors[call.getOperands().size()] - .implementSafe(translator, call, argValueList); + @Override Expression implementSafe(RexToLixTranslator translator, + RexCall call, List<Expression> argValList) { Review Comment: can be placed on the previous line -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org