tanclary commented on code in PR #3648:
URL: https://github.com/apache/calcite/pull/3648#discussion_r1467953149


##########
site/_docs/reference.md:
##########
@@ -2775,6 +2775,7 @@ In the following:
 | b f | 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 | | LOG2(numeric)                              | Returns the base 2 
logarithm of *numeric*

Review Comment:
   Remove the extra ` |`



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6188,6 +6188,29 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     f.checkNull("log(10, cast(null as real))");
   }
 
+  @Test void testLog2Func() {
+    final SqlOperatorFixture f0 = Fixtures.forOperators(true);
+    f0.setFor(SqlLibraryOperators.LOG2, VmName.EXPAND);
+    f0.checkFails("^log2(4)^",
+        "No match found for function signature LOG2\\(<NUMERIC>\\)", false);
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.MYSQL);

Review Comment:
   Even if the behavior does not vary across libraries, it is easy to test 
against all libraries using the `consumer` pattern. See any test that uses 
`forEachLibrary()` for examples.



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6188,6 +6188,29 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     f.checkNull("log(10, cast(null as real))");
   }
 
+  @Test void testLog2Func() {
+    final SqlOperatorFixture f0 = Fixtures.forOperators(true);
+    f0.setFor(SqlLibraryOperators.LOG2, VmName.EXPAND);
+    f0.checkFails("^log2(4)^",
+        "No match found for function signature LOG2\\(<NUMERIC>\\)", false);
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.MYSQL);
+    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)", "DOUBLE NOT NULL",
+        "NaN");
+    f.checkScalarApprox("log2(2/3)", "DOUBLE NOT NULL",

Review Comment:
   Using desmos, this should equal ~-0.5849625007



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6188,6 +6188,29 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     f.checkNull("log(10, cast(null as real))");
   }
 
+  @Test void testLog2Func() {
+    final SqlOperatorFixture f0 = Fixtures.forOperators(true);
+    f0.setFor(SqlLibraryOperators.LOG2, VmName.EXPAND);
+    f0.checkFails("^log2(4)^",
+        "No match found for function signature LOG2\\(<NUMERIC>\\)", false);
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.MYSQL);
+    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)", "DOUBLE NOT NULL",
+        "NaN");
+    f.checkScalarApprox("log2(2/3)", "DOUBLE NOT NULL",

Review Comment:
   wait what, why is log2(2/3) `-Infinity`?



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

Reply via email to