From 4f1140247e2f5059abd8f71b2ae54e3d1dcf1be2 Mon Sep 17 00:00:00 2001 From: Amit Dutta Date: Sun, 6 Oct 2024 10:05:39 -0700 Subject: [PATCH] Fix array_normalize to support int types. (#11173) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/11173 Presto java supports array normalize with int type (https://github.com/prestodb/presto/blob/832b071b3c74f65a6fe8386dc296b61f17192a7a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayNormalizeFunction.java#L56-L64). To support similar caess, registering array normalize with int types and extended tests. Reviewed By: xiaoxmeng, kgpai Differential Revision: D63931080 fbshipit-source-id: e58f1e0630b0a493d81ae18d16f9080e392e16c3 --- .../ArrayFunctionsRegistration.cpp | 5 +++++ .../prestosql/tests/ArrayNormalizeTest.cpp | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/velox/functions/prestosql/registration/ArrayFunctionsRegistration.cpp b/velox/functions/prestosql/registration/ArrayFunctionsRegistration.cpp index 506e047ba8b1..f3183f4d1577 100644 --- a/velox/functions/prestosql/registration/ArrayFunctionsRegistration.cpp +++ b/velox/functions/prestosql/registration/ArrayFunctionsRegistration.cpp @@ -308,6 +308,11 @@ void registerArrayFunctions(const std::string& prefix) { registerArrayFrequencyFunctions(prefix); registerArrayFrequencyFunctions(prefix); + registerArrayNormalizeFunctions(prefix); + registerArrayNormalizeFunctions(prefix); + registerArrayNormalizeFunctions(prefix); + registerArrayNormalizeFunctions(prefix); + registerArrayNormalizeFunctions(prefix); registerArrayNormalizeFunctions(prefix); registerArrayNormalizeFunctions(prefix); } diff --git a/velox/functions/prestosql/tests/ArrayNormalizeTest.cpp b/velox/functions/prestosql/tests/ArrayNormalizeTest.cpp index 5f40f84010f3..5493df0cc1eb 100644 --- a/velox/functions/prestosql/tests/ArrayNormalizeTest.cpp +++ b/velox/functions/prestosql/tests/ArrayNormalizeTest.cpp @@ -55,15 +55,17 @@ class ArrayNormalizeTest : public FunctionBaseTest { template void testArrayWithElementsEqualZero() { - auto input = makeArrayVector({{0.0, -0.0, 0.0}}); - auto p = makeConstant(2.0, input->size()); + auto input = makeArrayVector( + {{static_cast(0.0), static_cast(-0.0), static_cast(0.0)}}); + auto p = makeConstant(static_cast(2.0), input->size()); testExpr(input, {input, p}); } template void testArrayWithPLessThanZero() { - auto input = makeArrayVector({{1.0, 2.0, 3.0}}); - auto p = makeConstant(-1.0, input->size()); + auto input = makeArrayVector( + {{static_cast(1.0), static_cast(2.0), static_cast(3.0)}}); + auto p = makeConstant(static_cast(-1.0), input->size()); VELOX_ASSERT_THROW( testExpr(input, {input, p}), "array_normalize only supports non-negative p"); @@ -71,8 +73,9 @@ class ArrayNormalizeTest : public FunctionBaseTest { template void testArrayWithPEqualZero() { - auto vector = makeArrayVector({{1.0, -2.0, 3.0}}); - auto p = makeConstant(0.0, vector->size()); + auto vector = makeArrayVector( + {{static_cast(1.0), static_cast(-2.0), static_cast(3.0)}}); + auto p = makeConstant(static_cast(0.0), vector->size()); testExpr(vector, {vector, p}); } @@ -159,16 +162,19 @@ class ArrayNormalizeTest : public FunctionBaseTest { }; TEST_F(ArrayNormalizeTest, arrayWithElementsZero) { + testArrayWithElementsEqualZero(); testArrayWithElementsEqualZero(); testArrayWithElementsEqualZero(); } TEST_F(ArrayNormalizeTest, pLessThanZero) { + testArrayWithElementsEqualZero(); testArrayWithPLessThanZero(); testArrayWithPLessThanZero(); } TEST_F(ArrayNormalizeTest, pEqualsZero) { + testArrayWithPEqualZero(); testArrayWithPEqualZero(); testArrayWithPEqualZero(); } @@ -179,21 +185,25 @@ TEST_F(ArrayNormalizeTest, pLessThanOne) { } TEST_F(ArrayNormalizeTest, pEqualsOne) { + testArrayWithPEqualOne(); testArrayWithPEqualOne(); testArrayWithPEqualOne(); } TEST_F(ArrayNormalizeTest, limits) { + testArrayWithPEqualOne(); testArrayWithTypeLimits(); testArrayWithTypeLimits(); } TEST_F(ArrayNormalizeTest, nullValues) { + testArrayWithPEqualOne(); testArrayWithNullValues(); testArrayWithNullValues(); } TEST_F(ArrayNormalizeTest, differentValues) { + testArrayWithPEqualOne(); testArrayWithDifferentValues(); testArrayWithDifferentValues(); }