caicancai commented on code in PR #3689:
URL: https://github.com/apache/calcite/pull/3689#discussion_r1491839920
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6218,10 +6226,43 @@ void checkRegexpExtract(SqlOperatorFixture f0,
FunctionAlias functionAlias) {
isWithin(9.0, 0.000001));
f.checkScalarApprox("log(cast(10e-3 as real), 10)", "DOUBLE NOT NULL",
isWithin(-2.0, 0.000001));
+ f.checkScalarApprox("log(2.0/3, 100)", "DOUBLE NOT NULL",
+ isWithin(-0.08804562952784059, 0.000001));
+ f.checkScalarApprox("log(0.5, 2)", "DOUBLE NOT NULL",
+ isWithin(-1.0, 0.000001));
f.checkNull("log(cast(null as real), 10)");
f.checkNull("log(10, cast(null as real))");
}
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6224">[CALCITE-6224]
+ * Add LOG2 function (enabled in MYSQL, Spark library)</a>. */
+ @Test void testLog2Func() {
+ final SqlOperatorFixture f0 = fixture();
+ f0.checkFails("^log2(4)^",
+ "No match found for function signature LOG2\\(<NUMERIC>\\)", false);
+ final Consumer<SqlOperatorFixture> consumer = f -> {
+ f.setFor(SqlLibraryOperators.LOG2);
+ f.checkScalarApprox("log2(2)", "DOUBLE NOT NULL",
+ isWithin(1.0, 0.000001));
+ f.checkScalarApprox("log2(4)", "DOUBLE NOT NULL",
+ isWithin(2.0, 0.000001));
+ f.checkScalarApprox("log2(65536)", "DOUBLE NOT NULL",
+ isWithin(16.0, 0.000001));
+ f.checkScalarApprox("log2(2.0/3)", "DOUBLE NOT NULL",
+ isWithin(-0.5849625007211561, 0.000001));
+ f.checkScalarApprox("log2(4.0/3)", "DOUBLE NOT NULL",
+ isWithin(0.4150374992788435, 0.000001));
+ f.checkScalarApprox("log2(0.5)", "DOUBLE NOT NULL",
+ isWithin(-1.0, 0.000001));
+ f.checkScalarApprox("log2(-2)", "DOUBLE NOT NULL",
+ "NaN");
+ f.checkNull("log2(cast(null as real))");
Review Comment:
> At least in MySQL 8.0 LOG2(0) returns NULL. So this does not seem to be an
accurate implementation.
I will do the fix in another jira,
Discussion: https://issues.apache.org/jira/browse/CALCITE-6259
--
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]