mihaibudiu commented on code in PR #3711:
URL: https://github.com/apache/calcite/pull/3711#discussion_r1518332132


##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -4147,6 +4153,43 @@ private static List<Expression> args(RexCall call,
     }
   }
 
+  /** Implementor for the {@code LN}, {@code LOG}, and {@code LOG10} operators.
+   *
+   * <p>Handles all logarithm functions using log rules to determine the
+   * appropriate base (i.e. base e for LN).
+   */
+  private static class LogMSImplementor extends AbstractRexCallImplementor {

Review Comment:
   You should probably document that this is for MySQL and Spark.
   The part of the comment about determining the base is not very useful.



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6280,6 +6280,94 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     f0.forEachLibrary(list(SqlLibrary.MYSQL, SqlLibrary.SPARK), consumer);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6259";>[CALCITE-6259]
+   * Add LOG function (enabled in MYSQL, Spark library)</a>. */
+  @Test void testLogMSFunc() {
+    final SqlOperatorFixture f0 = Fixtures.forOperators(true);
+    f0.checkFails("^log(100, 10)^",
+        "No match found for function signature LOG\\(<NUMERIC>, <NUMERIC>\\)", 
false);
+    f0.setFor(SqlLibraryOperators.LOG_MS);
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkScalarApprox("log(10, 10)", "DOUBLE",
+          isWithin(1.0, 0.000001));
+      f.checkScalarApprox("log(64, 8)", "DOUBLE",
+          isWithin(2.0, 0.000001));
+      f.checkScalarApprox("log(27,3)", "DOUBLE",
+          isWithin(3.0, 0.000001));
+      f.checkScalarApprox("log(100, 10)", "DOUBLE",
+          isWithin(2.0, 0.000001));
+      f.checkScalarApprox("log(10, 100)", "DOUBLE",
+          isWithin(0.5, 0.000001));
+      f.checkScalarApprox("log(cast(10e6 as double), 10)", "DOUBLE",
+          isWithin(7.0, 0.000001));
+      f.checkScalarApprox("log(cast(10e8 as float), 10)", "DOUBLE",
+          isWithin(9.0, 0.000001));
+      f.checkScalarApprox("log(cast(10e-3 as real), 10)", "DOUBLE",
+          isWithin(-2.0, 0.000001));
+      f.checkNull("log(cast(null as real), 10)");
+      f.checkNull("log(10, cast(null as real))");
+      f.checkNull("log(0, 2)");
+      f.checkNull("log(0,-2)");
+      f.checkNull("log(0, +0.0)");
+      f.checkNull("log(0, 0.0)");
+      f.checkNull("log(null)");
+      f.checkNull("log(cast(null as real))");
+    };
+    f0.forEachLibrary(list(SqlLibrary.MYSQL, SqlLibrary.SPARK), consumer);
+  }
+
+//  /** Test case for
+//   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6259";>[CALCITE-6259]
+//   * Add LOG10 function (enabled in MYSQL, Spark library)</a>. */
+//  @Test void testLog10MSFunc() {

Review Comment:
   It doesn't look like this PR is ready for review yet.



##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -638,12 +640,16 @@ Builder populate() {
       defineMethod(EXP, BuiltInMethod.EXP.method, NullPolicy.STRICT);
       defineMethod(POWER, BuiltInMethod.POWER.method, NullPolicy.STRICT);
       defineMethod(ABS, BuiltInMethod.ABS.method, NullPolicy.STRICT);
-      defineMethod(LOG2, BuiltInMethod.LOG2.method, NullPolicy.STRICT);
 
       map.put(LN, new LogImplementor());
       map.put(LOG, new LogImplementor());
       map.put(LOG10, new LogImplementor());
 
+      map.put(LN, new LogMSImplementor());

Review Comment:
   map is a Java Map, you are overwriting the previous entry.



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

Reply via email to