NobiGo commented on code in PR #3789: URL: https://github.com/apache/calcite/pull/3789#discussion_r1650426631
########## core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java: ########## @@ -649,12 +650,14 @@ Builder populate() { defineMethod(POWER, BuiltInMethod.POWER.method, NullPolicy.STRICT); defineMethod(POWER_PG, BuiltInMethod.POWER_PG.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(LOG_MYSQL, new LogMysqlSparkImplementor()); Review Comment: I think LogMysqlImplementor is enough. ########## testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java: ########## @@ -6978,6 +6978,43 @@ 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 testLogMysqlSparkFunc() { + final SqlOperatorFixture f0 = fixture(); + f0.checkFails("^log(100, 10)^", + "No match found for function signature LOG\\(<NUMERIC>, <NUMERIC>\\)", false); + f0.setFor(SqlLibraryOperators.LOG_MYSQL); + 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))"); Review Comment: Please add test case cover log(0), LOG(-1). as describe in JIRA ########## site/_docs/reference.md: ########## @@ -2790,6 +2790,7 @@ In the following: | b f s | LENGTH(string) | Equivalent to `CHAR_LENGTH(string)` | h s | LEVENSHTEIN(string1, string2) | Returns the Levenshtein distance between *string1* and *string2* | b | LOG(numeric1 [, numeric2 ]) | Returns the logarithm of *numeric1* to base *numeric2*, or base e if *numeric2* is not present +| m s | LOG(numeric1 [, numeric2 ]) | Returns the logarithm of *numeric1* to base *numeric2*, or base e if *numeric2* is not present, or null if *numeric1* is 0 Review Comment: if *numeric1* is 0 or negative ? -- 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