aytrack commented on code in PR #47228: URL: https://github.com/apache/doris/pull/47228#discussion_r1930106747
########## regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy: ########## @@ -23,424 +23,434 @@ suite("fold_constant_numeric_arithmatic") { sql "set enable_fallback_to_original_planner=false" sql "set enable_fold_constant_by_be=false" - testFoldConst("SELECT truncate(123.456, -1)") -// testFoldConst("select pmod(-9223372036854775808,-1)") - //Coalesce function cases - testFoldConst("SELECT COALESCE(NULL, 5) AS coalesce_case_1") - testFoldConst("SELECT COALESCE(NULL, NULL, 7) AS coalesce_case_2") - testFoldConst("SELECT COALESCE(3, 5) AS coalesce_case_3") - testFoldConst("SELECT COALESCE(NULL, NULL) AS coalesce_case_4") - -//Round function cases - testFoldConst("SELECT ROUND(3.4) AS round_case_1") - testFoldConst("SELECT ROUND(3.5) AS round_case_2") - testFoldConst("SELECT ROUND(-3.4) AS round_case_3") - testFoldConst("SELECT ROUND(123.456, 2) AS round_case_4") //Rounding to 2 decimal places - -//Ceil function cases - testFoldConst("SELECT CEIL(3.4) AS ceil_case_1") - testFoldConst("SELECT CEIL(-3.4) AS ceil_case_2") - testFoldConst("SELECT CEIL(5.0) AS ceil_case_3") - -//Floor function cases - testFoldConst("SELECT FLOOR(3.7) AS floor_case_1") - testFoldConst("SELECT FLOOR(-3.7) AS floor_case_2") - testFoldConst("SELECT FLOOR(5.0) AS floor_case_3") - -//Exp function cases - testFoldConst("SELECT EXP(1) AS exp_case_1") //e^1 - testFoldConst("SELECT EXP(0) AS exp_case_2") //e^0 - testFoldConst("SELECT EXP(-1) AS exp_case_3") //e^-1 - -//Ln (natural logarithm) function cases - testFoldConst("SELECT LN(1) AS ln_case_1") //ln(1) = 0 - testFoldConst("SELECT LN(EXP(1)) AS ln_case_2") //ln(e) = 1 - testFoldConst("SELECT LN(0.5) AS ln_case_3") //ln(0.5) - -//Log10 function cases - testFoldConst("SELECT LOG10(100) AS log10_case_1") //log10(100) = 2 - testFoldConst("SELECT LOG10(1) AS log10_case_2") //log10(1) = 0 - testFoldConst("SELECT LOG10(1000) AS log10_case_3") //log10(1000) = 3 - -//Log2 function cases - testFoldConst("SELECT LOG2(2) AS log2_case_1") //log2(2) = 1 - testFoldConst("SELECT LOG2(8) AS log2_case_2") //log2(8) = 3 - testFoldConst("SELECT LOG2(1) AS log2_case_3") //log2(1) = 0 - -//Sqrt function cases - testFoldConst("SELECT SQRT(16) AS sqrt_case_1") //sqrt(16) = 4 - testFoldConst("SELECT SQRT(0) AS sqrt_case_2") //sqrt(0) = 0 - testFoldConst("SELECT SQRT(2) AS sqrt_case_3") //sqrt(2) - -//Power function cases - testFoldConst("SELECT POWER(2, 3) AS power_case_1") //2^3 = 8 - testFoldConst("SELECT POWER(10, 0) AS power_case_2") //10^0 = 1 - testFoldConst("SELECT POWER(5, -1) AS power_case_3") //5^-1 = 0.2 - -//Sin function cases - testFoldConst("SELECT SIN(PI() / 2) AS sin_case_1") //sin(π/2) = 1 - testFoldConst("SELECT SIN(0) AS sin_case_2") //sin(0) = 0 - testFoldConst("SELECT SIN(PI()) AS sin_case_3") //sin(π) - -//Cos function cases - testFoldConst("SELECT COS(PI()) AS cos_case_1") //cos(π) = -1 - testFoldConst("SELECT COS(0) AS cos_case_2") //cos(0) = 1 - testFoldConst("SELECT COS(PI() / 2) AS cos_case_3") //cos(π/2) - -//Tan function cases - testFoldConst("SELECT TAN(PI() / 4) AS tan_case_1") //tan(π/4) = 1 - testFoldConst("SELECT TAN(0) AS tan_case_2") //tan(0) = 0 - testFoldConst("SELECT TAN(PI()) AS tan_case_3") //tan(π) + //Abs function cases + testFoldConst("SELECT ABS(1)") + testFoldConst("SELECT ABS(0)") + testFoldConst("SELECT ABS(-1)") + testFoldConst("SELECT ABS(1.5)") + testFoldConst("SELECT ABS(-1.5)") + testFoldConst("SELECT ABS(1E308)") + testFoldConst("SELECT ABS(-1E308)") + testFoldConst("SELECT ABS(NULL)") // NULL handling + testFoldConst("SELECT ABS('')") // Empty string handling + testFoldConst("SELECT ABS('abc')") // Invalid input + testFoldConst("SELECT ABS(9223372036854775807)") // Max bigint + testFoldConst("SELECT ABS(-9223372036854775808)") // Min bigint //Acos function cases testFoldConst("SELECT ACOS(1) AS acos_case_1") //acos(1) = 0 testFoldConst("SELECT ACOS(0) AS acos_case_2") //acos(0) = π/2 testFoldConst("SELECT ACOS(-1) AS acos_case_3") //acos(-1) = π + testFoldConst("SELECT ACOS(0.5)") // Common value + testFoldConst("SELECT ACOS(-0.5)") // Negative common value + testFoldConst("SELECT ACOS(NULL)") // NULL handling + expectException({sql "SELECT ACOS(2)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 2 is out of boundary") + expectException({sql "SELECT ACOS(-2)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input -2 is out of boundary") + expectException({sql "SELECT ACOS(1.5)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") + expectException({sql "SELECT ACOS(-1.5)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input -1.5 is out of boundary") + expectException({sql "SELECT ACOS(1E308)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") + expectException({sql "SELECT ACOS(-1E308)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") //Asin function cases testFoldConst("SELECT ASIN(1) AS asin_case_1") //asin(1) = π/2 testFoldConst("SELECT ASIN(0) AS asin_case_2") //asin(0) = 0 testFoldConst("SELECT ASIN(-1) AS asin_case_3") //asin(-1) = -π/2 + testFoldConst("SELECT ASIN(0.5)") // Common value + testFoldConst("SELECT ASIN(-0.5)") // Negative common value + testFoldConst("SELECT ASIN(NULL)") // NULL handling + expectException({sql "SELECT ASIN(2)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 2 is out of boundary") + expectException({sql "SELECT ASIN(-2)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input -2 is out of boundary") + expectException({sql "SELECT ASIN(1.5)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") + expectException({sql "SELECT ASIN(-1.5)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input -1.5 is out of boundary") + expectException({sql "SELECT ASIN(1E308)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") + expectException({sql "SELECT ASIN(-1E308)"}, "errCode = 2, detailMessage = Not Supported: Not Supported: input 1.5 is out of boundary") //Atan function cases testFoldConst("SELECT ATAN(1) AS atan_case_1") //atan(1) = π/4 testFoldConst("SELECT ATAN(0) AS atan_case_2") //atan(0) = 0 testFoldConst("SELECT ATAN(-1) AS atan_case_3") //atan(-1) + testFoldConst("SELECT ATAN(1.5)") + testFoldConst("SELECT ATAN(-1.5)") + testFoldConst("SELECT ATAN(1E308)") + testFoldConst("SELECT ATAN(-1E308)") + testFoldConst("SELECT ATAN(NULL)") // NULL handling + testFoldConst("SELECT ATAN(PI())") // PI input + testFoldConst("SELECT ATAN(-PI())") // Negative PI input + testFoldConst("SELECT ATAN(1E-308)") // Very small positive number + testFoldConst("SELECT ATAN(-1E-308)") // Very small negative number //Atan2 function cases testFoldConst("SELECT ATAN2(1, 1) AS atan2_case_1") //atan2(1, 1) = π/4 testFoldConst("SELECT ATAN2(0, 1) AS atan2_case_2") //atan2(0, 1) = 0 testFoldConst("SELECT ATAN2(1, 0) AS atan2_case_3") //atan2(1, 0) = π/2 + testFoldConst("SELECT ATAN2(0, 0) AS atan2_case_exception") //undefined (returns NULL or error) + testFoldConst("SELECT ATAN2(1.5, 1.5)") + testFoldConst("SELECT ATAN2(-1.5, 1.5)") + testFoldConst("SELECT ATAN2(1E308, 1E308)") + testFoldConst("SELECT ATAN2(-1E308, 1E308)") + testFoldConst("SELECT ATAN2(NULL, 1)") // NULL y + testFoldConst("SELECT ATAN2(1, NULL)") // NULL x + testFoldConst("SELECT ATAN2(-1, -1)") // Both negative + testFoldConst("SELECT ATAN2(1E-308, 1E-308)") // Very small numbers -//Sign function cases - testFoldConst("SELECT SIGN(5) AS sign_case_1") //sign(5) = 1 - testFoldConst("SELECT SIGN(-5) AS sign_case_2") //sign(-5) = -1 - testFoldConst("SELECT SIGN(0) AS sign_case_3") //sign(0) = 0 - -//Bin function cases (binary conversion) +//Bin function cases testFoldConst("SELECT BIN(5) AS bin_case_1") //bin(5) = 101 testFoldConst("SELECT BIN(16) AS bin_case_2") //bin(16) = 10000 testFoldConst("SELECT BIN(255) AS bin_case_3") //bin(255) - -//BitCount function cases (count bits set to 1) + testFoldConst("SELECT BIN(-1) AS bin_case_exception") //returns NULL or error in some databases + testFoldConst("SELECT BIN(1E308)") + testFoldConst("SELECT BIN(-1E308)") + testFoldConst("SELECT BIN(0)") // Zero case + testFoldConst("SELECT BIN(NULL)") // NULL handling + testFoldConst("SELECT BIN(9223372036854775807)") // Max bigint + testFoldConst("SELECT BIN(-9223372036854775808)") // Min bigint + testFoldConst("SELECT BIN(2147483647)") // Max int + testFoldConst("SELECT BIN(-2147483648)") // Min int + +//BitCount function cases testFoldConst("SELECT BIT_COUNT(5) AS bitcount_case_1") //bitcount(5) = 2 (101 has two 1s) testFoldConst("SELECT BIT_COUNT(16) AS bitcount_case_2") //bitcount(16) = 1 - testFoldConst("SELECT BIT_COUNT(255) AS bitcount_case_3") //bitcount(255) - -//BitLength function cases - testFoldConst("SELECT BIT_LENGTH('5') AS bitlength_case_1") //bitlength(101) = 3 - testFoldConst("SELECT BIT_LENGTH('16') AS bitlength_case_2") //bitlength(10000) = 5 - testFoldConst("SELECT BIT_LENGTH('11111111') AS bitlength_case_3") //bitlength(11111111) - -//Cbrt (cube root) function cases + testFoldConst("SELECT BIT_COUNT(255) AS bitcount_case_3") //bitcount(255) = 8 + testFoldConst("SELECT BIT_COUNT(-1) AS bitcount_case_exception") + testFoldConst("SELECT BIT_COUNT(1E308)") + testFoldConst("SELECT BIT_COUNT(-1E308)") + testFoldConst("SELECT BIT_COUNT(0)") // Zero case + testFoldConst("SELECT BIT_COUNT(NULL)") // NULL handling + testFoldConst("SELECT BIT_COUNT(9223372036854775807)") // Max bigint + testFoldConst("SELECT BIT_COUNT(-9223372036854775808)") // Min bigint + testFoldConst("SELECT BIT_COUNT(2147483647)") // Max int + testFoldConst("SELECT BIT_COUNT(-2147483648)") // Min int + +//Cbrt function cases testFoldConst("SELECT CBRT(8) AS cbrt_case_1") //cbrt(8) = 2 testFoldConst("SELECT CBRT(-8) AS cbrt_case_2") //cbrt(-8) = -2 -// testFoldConst("SELECT CBRT(27) AS cbrt_case_3") //cbrt(27) - -//Cosh function cases (hyperbolic cosine) - testFoldConst("SELECT COSH(0) AS cosh_case_1") //cosh(0) = 1 -// testFoldConst("SELECT COSH(1) AS cosh_case_2") //cosh(1) -// testFoldConst("SELECT COSH(-1) AS cosh_case_3") //cosh(-1) - -//Tanh function cases (hyperbolic tangent) - testFoldConst("SELECT TANH(0) AS tanh_case_1") //tanh(0) = 0 - testFoldConst("SELECT TANH(1) AS tanh_case_2") //tanh(1) - testFoldConst("SELECT TANH(-1) AS tanh_case_3") //tanh(-1) + testFoldConst("SELECT CBRT(1E308)") + testFoldConst("SELECT CBRT(-1E308)") + testFoldConst("SELECT CBRT(0)") // Zero case + testFoldConst("SELECT CBRT(NULL)") // NULL handling + testFoldConst("SELECT CBRT(1)") // Unit case + testFoldConst("SELECT CBRT(-1)") // Negative unit case + testFoldConst("SELECT CBRT(27)") // Perfect cube + testFoldConst("SELECT CBRT(-27)") // Negative perfect cube -//Dexp function cases (double exp) - testFoldConst("SELECT EXP(2.0) AS dexp_case_1") //dexp(2.0) - testFoldConst("SELECT EXP(0.5) AS dexp_case_2") //dexp(0.5) - testFoldConst("SELECT EXP(-2.0) AS dexp_case_3") //dexp(-2.0) - -//Dlog10 function cases (double log base 10) - testFoldConst("SELECT LOG10(100.0) AS dlog10_case_1") //dlog10(100.0) = 2 - testFoldConst("SELECT LOG10(1.0) AS dlog10_case_2") //dlog10(1.0) = 0 - testFoldConst("SELECT LOG10(1000.0) AS dlog10_case_3") //dlog10(1000.0) - -//Dlog1 function cases (log base 1 is not commonly defined) +//Ceil function cases + testFoldConst("SELECT CEIL(3.4) AS ceil_case_1") + testFoldConst("SELECT CEIL(-3.4) AS ceil_case_2") + testFoldConst("SELECT CEIL(5.0) AS ceil_case_3") + testFoldConst("SELECT CEIL(1E308) AS ceil_case_overflow") + testFoldConst("SELECT CEIL(1E308)") + testFoldConst("SELECT CEIL(-1E308)") + testFoldConst("SELECT CEIL(NULL)") // NULL handling + testFoldConst("SELECT CEIL(0)") // Zero case + testFoldConst("SELECT CEIL(0.1)") // Small positive decimal + testFoldConst("SELECT CEIL(-0.1)") // Small negative decimal + testFoldConst("SELECT CEIL(9.99999999)") // Close to next integer + testFoldConst("SELECT CEIL(-9.99999999)") // Negative close to next integer Review Comment: ceil support a second params `T ceil(T x[, d])`, need to add some cases with the `d` param -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org