From 186647d4a35d05681febf4f53502b306aa6d511a Mon Sep 17 00:00:00 2001 From: Evgenij Ryazanov Date: Thu, 25 Jan 2024 20:58:37 +0800 Subject: [PATCH 1/3] Throw exception on invalid ASIN or ACOS argument as requried by the Standard --- .../h2/expression/function/MathFunction1.java | 6 +++ h2/src/main/org/h2/res/help.csv | 48 ++++++++++--------- .../test/scripts/functions/numeric/acos.sql | 9 ++++ .../test/scripts/functions/numeric/asin.sql | 9 ++++ 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/h2/src/main/org/h2/expression/function/MathFunction1.java b/h2/src/main/org/h2/expression/function/MathFunction1.java index f48b0d5026..38b51cae95 100644 --- a/h2/src/main/org/h2/expression/function/MathFunction1.java +++ b/h2/src/main/org/h2/expression/function/MathFunction1.java @@ -156,9 +156,15 @@ public Value getValue(SessionLocal session) { d = Math.tanh(d); break; case ASIN: + if (d < -1d || d > 1d) { + throw DbException.getInvalidValueException("ASIN() argument", d); + } d = Math.asin(d); break; case ACOS: + if (d < -1d || d > 1d) { + throw DbException.getInvalidValueException("ACOS() argument", d); + } d = Math.acos(d); break; case ATAN: diff --git a/h2/src/main/org/h2/res/help.csv b/h2/src/main/org/h2/res/help.csv index ffc91e508a..9337d97931 100644 --- a/h2/src/main/org/h2/res/help.csv +++ b/h2/src/main/org/h2/res/help.csv @@ -4845,8 +4845,10 @@ ABS(CAST(I AS BIGINT)) ACOS(numeric) "," Calculate the arc cosine. -See also Java ""Math.acos"". -This method returns a double. + +Argument must be between -1 and 1 inclusive. + +This function returns a double precision value. "," ACOS(D) " @@ -4855,8 +4857,10 @@ ACOS(D) ASIN(numeric) "," Calculate the arc sine. -See also Java ""Math.asin"". -This method returns a double. + +Argument must be between -1 and 1 inclusive. + +This function returns a double precision value. "," ASIN(D) " @@ -4865,8 +4869,8 @@ ASIN(D) ATAN(numeric) "," Calculate the arc tangent. -See also Java ""Math.atan"". -This method returns a double. + +This function returns a double precision value. "," ATAN(D) " @@ -4875,8 +4879,8 @@ ATAN(D) COS(numeric) "," Calculate the trigonometric cosine. -See also Java ""Math.cos"". -This method returns a double. + +This function returns a double precision value. "," COS(ANGLE) " @@ -4885,8 +4889,8 @@ COS(ANGLE) COSH(numeric) "," Calculate the hyperbolic cosine. -See also Java ""Math.cosh"". -This method returns a double. + +This function returns a double precision value. "," COSH(X) " @@ -4895,8 +4899,8 @@ COSH(X) @h2@ COT(numeric) "," Calculate the trigonometric cotangent (""1/TAN(ANGLE)""). -See also Java ""Math.*"" functions. -This method returns a double. + +This function returns a double precision value. "," COT(ANGLE) " @@ -4905,8 +4909,8 @@ COT(ANGLE) SIN(numeric) "," Calculate the trigonometric sine. -See also Java ""Math.sin"". -This method returns a double. + +This function returns a double precision value. "," SIN(ANGLE) " @@ -4915,8 +4919,8 @@ SIN(ANGLE) SINH(numeric) "," Calculate the hyperbolic sine. -See also Java ""Math.sinh"". -This method returns a double. + +This function returns a double precision value. "," SINH(ANGLE) " @@ -4925,8 +4929,8 @@ SINH(ANGLE) TAN(numeric) "," Calculate the trigonometric tangent. -See also Java ""Math.tan"". -This method returns a double. + +This function returns a double precision value. "," TAN(ANGLE) " @@ -4935,8 +4939,8 @@ TAN(ANGLE) TANH(numeric) "," Calculate the hyperbolic tangent. -See also Java ""Math.tanh"". -This method returns a double. + +This function returns a double precision value. "," TANH(X) " @@ -4945,8 +4949,8 @@ TANH(X) @h2@ ATAN2(numeric, numeric) "," Calculate the angle when converting the rectangular coordinates to polar coordinates. -See also Java ""Math.atan2"". -This method returns a double. + +This function returns a double precision value. "," ATAN2(X, Y) " diff --git a/h2/src/test/org/h2/test/scripts/functions/numeric/acos.sql b/h2/src/test/org/h2/test/scripts/functions/numeric/acos.sql index 9a6a689feb..5e07edd202 100644 --- a/h2/src/test/org/h2/test/scripts/functions/numeric/acos.sql +++ b/h2/src/test/org/h2/test/scripts/functions/numeric/acos.sql @@ -8,3 +8,12 @@ select acos(null) vn, acos(-1) r1; > ---- ----------------- > null 3.141592653589793 > rows: 1 + +SELECT ACOS(-1.1); +> exception INVALID_VALUE_2 + +SELECT ACOS(1.1); +> exception INVALID_VALUE_2 + +SELECT ACOS(CAST('Infinity' AS DOUBLE PRECISION)); +> exception INVALID_VALUE_2 diff --git a/h2/src/test/org/h2/test/scripts/functions/numeric/asin.sql b/h2/src/test/org/h2/test/scripts/functions/numeric/asin.sql index c653bea45a..3eccdec8d1 100644 --- a/h2/src/test/org/h2/test/scripts/functions/numeric/asin.sql +++ b/h2/src/test/org/h2/test/scripts/functions/numeric/asin.sql @@ -8,3 +8,12 @@ select asin(null) vn, asin(-1) r1; > ---- ------------------- > null -1.5707963267948966 > rows: 1 + +SELECT ASIN(-1.1); +> exception INVALID_VALUE_2 + +SELECT ASIN(1.1); +> exception INVALID_VALUE_2 + +SELECT ASIN(CAST('Infinity' AS DOUBLE PRECISION)); +> exception INVALID_VALUE_2 From e1cabe389ec68d78b026917ad2bed4566b7d32b6 Mon Sep 17 00:00:00 2001 From: Evgenij Ryazanov Date: Thu, 25 Jan 2024 22:15:49 +0800 Subject: [PATCH 2/3] Fix MVPrimaryIndex.extractPKFromRow() for other numeric data types --- h2/src/docsrc/html/changelog.html | 2 + .../org/h2/mvstore/db/MVPrimaryIndex.java | 36 +- h2/src/main/org/h2/value/Value.java | 7 +- h2/src/test/org/h2/test/scripts/indexes.sql | 452 ++++++++++++++++++ 4 files changed, 491 insertions(+), 6 deletions(-) diff --git a/h2/src/docsrc/html/changelog.html b/h2/src/docsrc/html/changelog.html index 09fbd1e921..56c4b60399 100644 --- a/h2/src/docsrc/html/changelog.html +++ b/h2/src/docsrc/html/changelog.html @@ -21,6 +21,8 @@

Change Log

Next Version (unreleased)