From 37d8ad67ebc78822c9ea776c5302254a772d8762 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Fri, 7 Jun 2024 12:09:26 +0800 Subject: [PATCH] Revert PR 9516 --- velox/docs/functions/spark/array.rst | 12 +-- velox/functions/sparksql/ArraySizeFunction.h | 34 -------- velox/functions/sparksql/Register.cpp | 4 - .../sparksql/tests/ArraySizeTest.cpp | 80 ------------------- velox/functions/sparksql/tests/CMakeLists.txt | 1 - 5 files changed, 6 insertions(+), 125 deletions(-) delete mode 100644 velox/functions/sparksql/ArraySizeFunction.h delete mode 100644 velox/functions/sparksql/tests/ArraySizeTest.cpp diff --git a/velox/docs/functions/spark/array.rst b/velox/docs/functions/spark/array.rst index 8fa1ec7f028c6..631c863defe93 100644 --- a/velox/docs/functions/spark/array.rst +++ b/velox/docs/functions/spark/array.rst @@ -101,12 +101,6 @@ Array Functions SELECT array_repeat(100, 0); -- [] SELECT array_repeat(100, -1); -- [] -.. spark:function:: array_size(array(E)) -> integer - - Returns the size of the array. :: - - SELECT array_size(array(1, 2, 3)); -- 3 - .. spark:function:: array_sort(array(E)) -> array(E) Returns an array which has the sorted order of the input array(E). The elements of array(E) must @@ -173,6 +167,12 @@ Array Functions if :doc:`spark.legacy_size_of_null <../../configs>` is set to false. Otherwise, returns -1 for null input. +.. spark:function:: size(array(E), legacyOfNull) -> bigint + + Returns the size of the array. Returns null for null input if `legacyOfNull` + is set to false, which is the behavior of Spark's `array_size` function. + Otherwise, returns -1 for null input. + .. spark:function:: sort_array(array(E)) -> array(E) Returns an array which has the sorted order of the input array. The elements of array must diff --git a/velox/functions/sparksql/ArraySizeFunction.h b/velox/functions/sparksql/ArraySizeFunction.h deleted file mode 100644 index e7857815fe2bf..0000000000000 --- a/velox/functions/sparksql/ArraySizeFunction.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include -#include "velox/functions/Macros.h" - -namespace facebook::velox::functions::sparksql { - -template -struct ArraySizeFunction { - VELOX_DEFINE_FUNCTION_TYPES(T); - - FOLLY_ALWAYS_INLINE void call( - int32_t& out, - const arg_type>& inputArray) { - out = inputArray.size(); - } -}; -} // namespace facebook::velox::functions::sparksql diff --git a/velox/functions/sparksql/Register.cpp b/velox/functions/sparksql/Register.cpp index 0c945a5931be4..5bb33aa1c6042 100644 --- a/velox/functions/sparksql/Register.cpp +++ b/velox/functions/sparksql/Register.cpp @@ -30,7 +30,6 @@ #include "velox/functions/prestosql/URLFunctions.h" #include "velox/functions/sparksql/ArrayFlattenFunction.h" #include "velox/functions/sparksql/ArrayMinMaxFunction.h" -#include "velox/functions/sparksql/ArraySizeFunction.h" #include "velox/functions/sparksql/ArraySort.h" #include "velox/functions/sparksql/Bitwise.h" #include "velox/functions/sparksql/DateTimeFunctions.h" @@ -165,9 +164,6 @@ inline void registerArrayMinMaxFunctions(const std::string& prefix) { void registerFunctions(const std::string& prefix) { registerAllSpecialFormGeneralFunctions(); - registerFunction>( - {prefix + "array_size"}); - // Register size functions registerSize(prefix + "size"); diff --git a/velox/functions/sparksql/tests/ArraySizeTest.cpp b/velox/functions/sparksql/tests/ArraySizeTest.cpp deleted file mode 100644 index 1591ff484a9a3..0000000000000 --- a/velox/functions/sparksql/tests/ArraySizeTest.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "velox/functions/sparksql/tests/SparkFunctionBaseTest.h" -#include "velox/type/Timestamp.h" - -using namespace facebook::velox; -using namespace facebook::velox::test; -using namespace facebook::velox::functions::test; - -namespace facebook::velox::functions::sparksql::test { -namespace { - -class ArraySizeTest : public SparkFunctionBaseTest { - protected: - template - int32_t arraySize(const std::vector>& input) { - auto row = makeRowVector({makeNullableArrayVector( - std::vector>>{input})}); - return evaluateOnce("array_size(c0)", row).value(); - } -}; - -TEST_F(ArraySizeTest, boolean) { - EXPECT_EQ(arraySize({true, false}), 2); - EXPECT_EQ(arraySize({true}), 1); - EXPECT_EQ(arraySize({}), 0); - EXPECT_EQ(arraySize({true, false, true, std::nullopt}), 4); -} - -TEST_F(ArraySizeTest, smallint) { - EXPECT_EQ(arraySize({}), 0); - EXPECT_EQ(arraySize({1}), 1); - EXPECT_EQ(arraySize({std::nullopt}), 1); - EXPECT_EQ(arraySize({std::nullopt, 1}), 2); -} - -TEST_F(ArraySizeTest, real) { - EXPECT_EQ(arraySize({}), 0); - EXPECT_EQ(arraySize({1.1}), 1); - EXPECT_EQ(arraySize({std::nullopt}), 1); - EXPECT_EQ(arraySize({std::nullopt, 1.1}), 2); -} - -TEST_F(ArraySizeTest, varchar) { - EXPECT_EQ(arraySize({"red", "blue"}), 2); - EXPECT_EQ( - arraySize({std::nullopt, "blue", "yellow", "orange"}), 4); - EXPECT_EQ(arraySize({}), 0); - EXPECT_EQ(arraySize({std::nullopt}), 1); -} - -TEST_F(ArraySizeTest, integer) { - EXPECT_EQ(arraySize({1, 2}), 2); -} - -TEST_F(ArraySizeTest, timestamp) { - auto ts = [](int64_t micros) { return Timestamp::fromMicros(micros); }; - EXPECT_EQ(arraySize({}), 0); - EXPECT_EQ(arraySize({std::nullopt}), 1); - EXPECT_EQ(arraySize({ts(0), ts(1)}), 2); -} -} // namespace -} // namespace facebook::velox::functions::sparksql::test diff --git a/velox/functions/sparksql/tests/CMakeLists.txt b/velox/functions/sparksql/tests/CMakeLists.txt index 56b3fea8da6bf..af4b4c3f66dab 100644 --- a/velox/functions/sparksql/tests/CMakeLists.txt +++ b/velox/functions/sparksql/tests/CMakeLists.txt @@ -19,7 +19,6 @@ add_executable( ArrayGetTest.cpp ArrayMaxTest.cpp ArrayMinTest.cpp - ArraySizeTest.cpp ArraySortTest.cpp ArrayShuffleTest.cpp ArgGeneratorTest.cpp