提交 fe9b5e70 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

Support for COSH, SINH, and TANH functions.

上级 70ef2e60
...@@ -2406,6 +2406,16 @@ This method returns a double. ...@@ -2406,6 +2406,16 @@ This method returns a double.
COS(ANGLE) COS(ANGLE)
" "
"Functions (Numeric)","COSH","
COSH(double)
","
Calculate the hyperbolic cosine.
See also Java ""Math.cosh"".
This method returns a double.
","
COSH(X)
"
"Functions (Numeric)","COT"," "Functions (Numeric)","COT","
COT(double) COT(double)
"," ","
...@@ -2426,6 +2436,16 @@ This method returns a double. ...@@ -2426,6 +2436,16 @@ This method returns a double.
SIN(ANGLE) SIN(ANGLE)
" "
"Functions (Numeric)","SINH","
SINH(double)
","
Calculate the hyperbolic sine.
See also Java ""Math.sinh"".
This method returns a double.
","
SINH(ANGLE)
"
"Functions (Numeric)","TAN"," "Functions (Numeric)","TAN","
TAN(double) TAN(double)
"," ","
...@@ -2436,6 +2456,16 @@ This method returns a double. ...@@ -2436,6 +2456,16 @@ This method returns a double.
TAN(ANGLE) TAN(ANGLE)
" "
"Functions (Numeric)","TANH","
TANH(double)
","
Calculate the hyperbolic tangent.
See also Java ""Math.tanh"".
This method returns a double.
","
TANH(X)
"
"Functions (Numeric)","ATAN2"," "Functions (Numeric)","ATAN2","
ATAN2(double, double) ATAN2(double, double)
"," ","
......
...@@ -19,7 +19,8 @@ Change Log ...@@ -19,7 +19,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Support for the % operator (modulo) thanks to Noel Grandin. <li>Support for COSH, SINH, and TANH functions.
</li><li>Support for the % operator (modulo) thanks to Noel Grandin.
</li><li>Issue 288: Some right outer join queries failed to produce the correct result or </li><li>Issue 288: Some right outer join queries failed to produce the correct result or
threw exceptions such as "column x must be in the group by list". threw exceptions such as "column x must be in the group by list".
</li><li>Some right outer joins with invalid column referenced (typos) threw a NullPointerException instead of </li><li>Some right outer joins with invalid column referenced (typos) threw a NullPointerException instead of
......
...@@ -231,7 +231,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>. ...@@ -231,7 +231,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Integrate spatial functions from http://geosysin.iict.ch/irstv-trac/wiki/H2spatial/Download </li><li>Integrate spatial functions from http://geosysin.iict.ch/irstv-trac/wiki/H2spatial/Download
</li><li>Cluster: hot deploy (adding a node at runtime). </li><li>Cluster: hot deploy (adding a node at runtime).
</li><li>Support DatabaseMetaData.insertsAreDetected: updatable result sets should detect inserts. </li><li>Support DatabaseMetaData.insertsAreDetected: updatable result sets should detect inserts.
</li><li>Support COSH, SINH, and TANH functions
</li><li>Oracle: support DECODE method (convert to CASE WHEN). </li><li>Oracle: support DECODE method (convert to CASE WHEN).
</li><li>Native search: support "phrase search", wildcard search (* and ?), case-insensitive search, boolean operators, and grouping </li><li>Native search: support "phrase search", wildcard search (* and ?), case-insensitive search, boolean operators, and grouping
</li><li>Improve documentation of access rights. </li><li>Improve documentation of access rights.
......
...@@ -73,7 +73,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -73,7 +73,7 @@ public class Function extends Expression implements FunctionCall {
CEILING = 8, COS = 9, COT = 10, DEGREES = 11, EXP = 12, FLOOR = 13, LOG = 14, LOG10 = 15, MOD = 16, CEILING = 8, COS = 9, COT = 10, DEGREES = 11, EXP = 12, FLOOR = 13, LOG = 14, LOG10 = 15, MOD = 16,
PI = 17, POWER = 18, RADIANS = 19, RAND = 20, ROUND = 21, ROUNDMAGIC = 22, SIGN = 23, SIN = 24, SQRT = 25, PI = 17, POWER = 18, RADIANS = 19, RAND = 20, ROUND = 21, ROUNDMAGIC = 22, SIGN = 23, SIN = 24, SQRT = 25,
TAN = 26, TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30, DECRYPT = 31, COMPRESS = 32, TAN = 26, TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30, DECRYPT = 31, COMPRESS = 32,
EXPAND = 33, ZERO = 34, RANDOM_UUID = 35; EXPAND = 33, ZERO = 34, RANDOM_UUID = 35, COSH = 36, SINH = 37, TANH = 38;
public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52, CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55, public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52, CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55,
HEXTORAW = 56, INSERT = 57, INSTR = 58, LCASE = 59, LEFT = 60, LENGTH = 61, LOCATE = 62, LTRIM = 63, HEXTORAW = 56, INSERT = 57, INSTR = 58, LCASE = 59, LEFT = 60, LENGTH = 61, LOCATE = 62, LTRIM = 63,
...@@ -165,6 +165,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -165,6 +165,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("BITXOR", BITXOR, 2, Value.LONG); addFunction("BITXOR", BITXOR, 2, Value.LONG);
addFunction("CEILING", CEILING, 1, Value.DOUBLE); addFunction("CEILING", CEILING, 1, Value.DOUBLE);
addFunction("COS", COS, 1, Value.DOUBLE); addFunction("COS", COS, 1, Value.DOUBLE);
addFunction("COSH", COSH, 1, Value.DOUBLE);
addFunction("COT", COT, 1, Value.DOUBLE); addFunction("COT", COT, 1, Value.DOUBLE);
addFunction("DEGREES", DEGREES, 1, Value.DOUBLE); addFunction("DEGREES", DEGREES, 1, Value.DOUBLE);
addFunction("EXP", EXP, 1, Value.DOUBLE); addFunction("EXP", EXP, 1, Value.DOUBLE);
...@@ -182,8 +183,10 @@ public class Function extends Expression implements FunctionCall { ...@@ -182,8 +183,10 @@ public class Function extends Expression implements FunctionCall {
addFunction("ROUNDMAGIC", ROUNDMAGIC, 1, Value.DOUBLE); addFunction("ROUNDMAGIC", ROUNDMAGIC, 1, Value.DOUBLE);
addFunction("SIGN", SIGN, 1, Value.INT); addFunction("SIGN", SIGN, 1, Value.INT);
addFunction("SIN", SIN, 1, Value.DOUBLE); addFunction("SIN", SIN, 1, Value.DOUBLE);
addFunction("SINH", SINH, 1, Value.DOUBLE);
addFunction("SQRT", SQRT, 1, Value.DOUBLE); addFunction("SQRT", SQRT, 1, Value.DOUBLE);
addFunction("TAN", TAN, 1, Value.DOUBLE); addFunction("TAN", TAN, 1, Value.DOUBLE);
addFunction("TANH", TANH, 1, Value.DOUBLE);
addFunction("TRUNCATE", TRUNCATE, 2, Value.DOUBLE); addFunction("TRUNCATE", TRUNCATE, 2, Value.DOUBLE);
addFunction("HASH", HASH, 3, Value.BYTES); addFunction("HASH", HASH, 3, Value.BYTES);
addFunction("ENCRYPT", ENCRYPT, 3, Value.BYTES); addFunction("ENCRYPT", ENCRYPT, 3, Value.BYTES);
...@@ -447,6 +450,9 @@ public class Function extends Expression implements FunctionCall { ...@@ -447,6 +450,9 @@ public class Function extends Expression implements FunctionCall {
case COS: case COS:
result = ValueDouble.get(Math.cos(v0.getDouble())); result = ValueDouble.get(Math.cos(v0.getDouble()));
break; break;
case COSH:
result = ValueDouble.get(Math.cosh(v0.getDouble()));
break;
case COT: { case COT: {
double d = Math.tan(v0.getDouble()); double d = Math.tan(v0.getDouble());
if (d == 0.0) { if (d == 0.0) {
...@@ -492,12 +498,18 @@ public class Function extends Expression implements FunctionCall { ...@@ -492,12 +498,18 @@ public class Function extends Expression implements FunctionCall {
case SIN: case SIN:
result = ValueDouble.get(Math.sin(v0.getDouble())); result = ValueDouble.get(Math.sin(v0.getDouble()));
break; break;
case SINH:
result = ValueDouble.get(Math.sinh(v0.getDouble()));
break;
case SQRT: case SQRT:
result = ValueDouble.get(Math.sqrt(v0.getDouble())); result = ValueDouble.get(Math.sqrt(v0.getDouble()));
break; break;
case TAN: case TAN:
result = ValueDouble.get(Math.tan(v0.getDouble())); result = ValueDouble.get(Math.tan(v0.getDouble()));
break; break;
case TANH:
result = ValueDouble.get(Math.tanh(v0.getDouble()));
break;
case SECURE_RAND: case SECURE_RAND:
result = ValueBytes.getNoCopy(MathUtils.secureRandomBytes(v0.getInt())); result = ValueBytes.getNoCopy(MathUtils.secureRandomBytes(v0.getInt()));
break; break;
......
...@@ -60,6 +60,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -60,6 +60,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testDeterministic(); testDeterministic();
testTransactionId(); testTransactionId();
testPrecision(); testPrecision();
testMathFunctions();
testVarArgs(); testVarArgs();
testAggregate(); testAggregate();
testFunctions(); testFunctions();
...@@ -274,6 +275,21 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -274,6 +275,21 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn.close(); conn.close();
} }
private void testMathFunctions() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL SINH(50)");
assertTrue(rs.next());
assertEquals(Math.sinh(50), rs.getDouble(1));
rs = stat.executeQuery("CALL COSH(50)");
assertTrue(rs.next());
assertEquals(Math.cosh(50), rs.getDouble(1));
rs = stat.executeQuery("CALL TANH(50)");
assertTrue(rs.next());
assertEquals(Math.tanh(50), rs.getDouble(1));
conn.close();
}
private void testVarArgs() throws SQLException { private void testVarArgs() throws SQLException {
//## Java 1.5 begin ## //## Java 1.5 begin ##
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论