Skip to content

Commit

Permalink
[fix](nereids) acos function should return null literal instead of Na…
Browse files Browse the repository at this point in the history
…N value (#37932)

acos(cast(1.1 as double)) should return NULL instead of NaN
  • Loading branch information
starocean999 authored Jul 17, 2024
1 parent 8e24d8f commit dee9715
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import org.apache.doris.nereids.trees.expressions.literal.FloatLiteral;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.types.DoubleType;

import java.math.BigInteger;
import java.security.SecureRandom;
Expand Down Expand Up @@ -90,9 +92,17 @@ public static Expression abs(DecimalV3Literal literal) {
return new DecimalV3Literal(literal.getValue().abs());
}

/**
* acos scalar function
*/
@ExecFunction(name = "acos", argTypes = {"DOUBLE"}, returnType = "DOUBLE")
public static Expression acos(DoubleLiteral literal) {
return new DoubleLiteral(Math.acos(literal.getValue()));
double result = Math.acos(literal.getValue());
if (Double.isNaN(result)) {
return new NullLiteral(DoubleType.INSTANCE);
} else {
return new DoubleLiteral(result);
}
}

@ExecFunction(name = "append_trailing_char_if_absent", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR")
Expand Down
26 changes: 16 additions & 10 deletions regression-test/data/nereids_function_p0/scalar_function/A.out
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
\N
\N

-- !sql_acos_Double_NAN --
\N

-- !sql_acos_Double_NULL --
\N

-- !sql_append_trailing_char_if_absent_Varchar_Varchar --
\N
\N
Expand Down Expand Up @@ -437,29 +443,29 @@
-- !sql_atan2_Double --
\N
1.4711276743037345
1.3734007669450159
1.373400766945016
1.2793395323170296
1.1902899496825317
1.1071487177940904
1.0303768265243125
0.960070362405688
0.89605538457134393
0.8960553845713439
0.83798122500839
0.78539816339744828
0.73781506012046483
0.69473827619670314
0.7853981633974483
0.7378150601204648
0.6947382761967031

-- !sql_atan2_Double_notnull --
1.4711276743037345
1.3734007669450159
1.373400766945016
1.2793395323170296
1.1902899496825317
1.1071487177940904
1.0303768265243125
0.960070362405688
0.89605538457134393
0.8960553845713439
0.83798122500839
0.78539816339744828
0.73781506012046483
0.69473827619670314
0.7853981633974483
0.7378150601204648
0.6947382761967031

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ suite("nereids_scalar_fn_A") {
qt_sql_abs_DecimalV2_notnull "select abs(kdcmls1) from fn_test_not_nullable order by kdcmls1"
qt_sql_acos_Double "select acos(kdbl) from fn_test order by kdbl"
qt_sql_acos_Double_notnull "select acos(kdbl) from fn_test_not_nullable order by kdbl"
qt_sql_acos_Double_NAN "select acos(cast(1.1 as double))"
qt_sql_acos_Double_NULL "select acos(null)"
sql "select aes_decrypt(kvchrs1, kvchrs1) from fn_test order by kvchrs1, kvchrs1"
sql "select aes_decrypt(kvchrs1, kvchrs1) from fn_test_not_nullable order by kvchrs1, kvchrs1"
sql "select aes_decrypt(kstr, kstr) from fn_test order by kstr, kstr"
Expand Down

0 comments on commit dee9715

Please sign in to comment.