alex-plekhanov commented on code in PR #11478:
URL: https://github.com/apache/ignite/pull/11478#discussion_r1746044336


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

Review Comment:
   This logic was copied as is from calcite. I wouldn't change it without a 
strong reason. 



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/fun/IgniteStdSqlOperatorTable.java:
##########
@@ -291,6 +292,9 @@ public IgniteStdSqlOperatorTable() {
         register(SqlStdOperatorTable.IS_NOT_JSON_ARRAY);
         register(SqlStdOperatorTable.IS_NOT_JSON_SCALAR);
 
+        // Aggregate functions.
+        register(SqlInternalOperators.LITERAL_AGG); // Internal operator, not 
implemented, required for serialization.

Review Comment:
   It's not implemented in RexImpTable, it processed in special way, by 
aggregates.



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexImpTable.java:
##########
@@ -391,31 +402,30 @@ public class RexImpTable {
         map.put(IS_NOT_FALSE, new IsNotFalseImplementor());
 
         // LIKE and SIMILAR
-        final MethodImplementor likeImplementor =
-            new MethodImplementor(BuiltInMethod.LIKE.method, NullPolicy.STRICT,
-                false);
-        map.put(LIKE, likeImplementor);
-        map.put(NOT_LIKE, likeImplementor);
-        final MethodImplementor similarImplementor =
-            new MethodImplementor(BuiltInMethod.SIMILAR.method, 
NullPolicy.STRICT,
-                false);
-        map.put(SIMILAR_TO, similarImplementor);
-        map.put(NOT_SIMILAR_TO, NotImplementor.of(similarImplementor));
+        defineReflective(LIKE, BuiltInMethod.LIKE.method,
+            BuiltInMethod.LIKE_ESCAPE.method);
+        defineReflective(ILIKE, BuiltInMethod.ILIKE.method,
+            BuiltInMethod.ILIKE_ESCAPE.method);
+        defineReflective(RLIKE, BuiltInMethod.RLIKE.method);
+        defineReflective(SIMILAR_TO, BuiltInMethod.SIMILAR.method,

Review Comment:
   TO_CHAR - it's a function from Oracle dialect. Not sure we need it. 



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexImpTable.java:
##########
@@ -321,12 +328,16 @@ public class RexImpTable {
         defineMethod(MOD, "mod", NullPolicy.STRICT);
         defineMethod(EXP, "exp", NullPolicy.STRICT);
         defineMethod(POWER, "power", NullPolicy.STRICT);
-        defineMethod(LN, "ln", NullPolicy.STRICT);
-        defineMethod(LOG10, "log10", NullPolicy.STRICT);
         defineMethod(ABS, "abs", NullPolicy.STRICT);
 
-        map.put(RAND, new RandImplementor());
-        map.put(RAND_INTEGER, new RandIntegerImplementor());
+        map.put(LN, new LogImplementor());
+        map.put(LOG, new LogImplementor());
+        map.put(LOG10, new LogImplementor());

Review Comment:
   See coment about ASINH, ACOSH, ATANH



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

Reply via email to