xuzifu666 commented on code in PR #4720:
URL: https://github.com/apache/calcite/pull/4720#discussion_r2658866204


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -2561,6 +2561,15 @@ private static RelDataType 
deriveTypeMapFromEntries(SqlOperatorBinding opBinding
           OperandTypes.NUMERIC,
           SqlFunctionCategory.STRING);
 
+  /** The {@code HYPOT(numeric1, numeric2)} function; returns
+   * sqrt(numeric1^2 + numeric2^2) without intermediate overflow or underflow. 
*/
+  @LibraryOperator(libraries = {SPARK})

Review Comment:
   I see that other databases also support the ```hypot``` function, such as 
ClickHouse 
(https://clickhouse.com/docs/sql-reference/functions/math-functions#hypot). Is 
it possible for us to use this PR to enable support for all databases in the 
library that support this function?



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10018,6 +10018,36 @@ void checkArrayReverseFunc(SqlOperatorFixture f0, 
SqlFunction function,
     f0.forEachLibrary(list(SqlLibrary.BIG_QUERY, SqlLibrary.SPARK), consumer);
   }
 
+  /** Test case for <a 
href="https://issues.apache.org/jira/browse/CALCITE-6066";>
+   * [CALCITE-6066] Add HYPOT function (enabled in Spark library)</a>. */
+  @Test void testHypotFunc() {
+    final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.HYPOT);
+    f0.checkFails("^hypot(3, 4)^",
+        "No match found for function signature HYPOT\\(<NUMERIC>, 
<NUMERIC>\\)",
+        false);
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+    f.checkScalarApprox("hypot(3, 4)", "DOUBLE NOT NULL",
+        isWithin(5.0000d, 0.0001d));
+    f.checkScalarApprox("hypot(3.0, cast(4 as bigint))", "DOUBLE NOT NULL",
+        isWithin(5.0000d, 0.0001d));
+    f.checkScalarApprox("hypot(cast(-2 as bigint), cast(-4 as bigint))",
+        "DOUBLE NOT NULL",
+        isWithin(4.4721d, 0.0001d));
+    f.checkScalarApprox("hypot(cast(3.0 as double), cast(4.0 as double))",

Review Comment:
   What happens with unsigned types here? Perhaps we could add a test like 
this, also including for float types.



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