Skip to content

Commit

Permalink
Keep deleted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Jun 25, 2024
1 parent b61ad23 commit 41ed291
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions velox/functions/sparksql/tests/SizeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
#include <string>

#include <gtest/gtest.h>
#include <velox/core/QueryConfig.h>
#include <optional>
#include "velox/functions/sparksql/tests/SparkFunctionBaseTest.h"
#include "velox/type/Timestamp.h"

using namespace facebook::velox;
using namespace facebook::velox::exec;
Expand Down Expand Up @@ -48,10 +51,11 @@ class SizeTest : public SparkFunctionBaseTest {
}
}

void setConfig(std::string configStr, bool value) {
execCtx_.queryCtx()->testingOverrideConfigUnsafe({
{configStr, std::to_string(value)},
});
template <typename T>
int32_t testArraySize(const std::vector<std::optional<T>>& input) {
auto row = makeRowVector({makeNullableArrayVector(
std::vector<std::vector<std::optional<T>>>{input})});
return evaluateOnce<int32_t>("size(c0, false)", row).value();
}

static inline vector_size_t valueAt(vector_size_t idx) {
Expand All @@ -77,7 +81,7 @@ TEST_F(SizeTest, legacySizeOfNull) {
}

// Ensure that out is set to null for null input if legacySizeOfNull = false.
TEST_F(SizeTest, notLegacySizeOfNull) {
TEST_F(SizeTest, size) {
vector_size_t numRows = 100;
auto arrayVector =
makeArrayVector<int64_t>(numRows, sizeAt, valueAt, nullEvery(1));
Expand All @@ -87,4 +91,45 @@ TEST_F(SizeTest, notLegacySizeOfNull) {
testSize(mapVector, numRows);
}

TEST_F(SizeTest, boolean) {
EXPECT_EQ(testArraySize<bool>({true, false}), 2);
EXPECT_EQ(testArraySize<bool>({true}), 1);
EXPECT_EQ(testArraySize<bool>({}), 0);
EXPECT_EQ(testArraySize<bool>({true, false, true, std::nullopt}), 4);
}

TEST_F(SizeTest, smallint) {
EXPECT_EQ(testArraySize<int8_t>({}), 0);
EXPECT_EQ(testArraySize<int8_t>({1}), 1);
EXPECT_EQ(testArraySize<int8_t>({std::nullopt}), 1);
EXPECT_EQ(testArraySize<int8_t>({std::nullopt, 1}), 2);
}

TEST_F(SizeTest, real) {
EXPECT_EQ(testArraySize<float>({}), 0);
EXPECT_EQ(testArraySize<float>({1.1}), 1);
EXPECT_EQ(testArraySize<float>({std::nullopt}), 1);
EXPECT_EQ(testArraySize<float>({std::nullopt, 1.1}), 2);
}

TEST_F(SizeTest, varchar) {
EXPECT_EQ(testArraySize<std::string>({"red", "blue"}), 2);
EXPECT_EQ(
testArraySize<std::string>({std::nullopt, "blue", "yellow", "orange"}),
4);
EXPECT_EQ(testArraySize<std::string>({}), 0);
EXPECT_EQ(testArraySize<std::string>({std::nullopt}), 1);
}

TEST_F(SizeTest, integer) {
EXPECT_EQ(testArraySize<int32_t>({1, 2}), 2);
}

TEST_F(SizeTest, timestamp) {
auto ts = [](int64_t micros) { return Timestamp::fromMicros(micros); };
EXPECT_EQ(testArraySize<Timestamp>({}), 0);
EXPECT_EQ(testArraySize<Timestamp>({std::nullopt}), 1);
EXPECT_EQ(testArraySize<Timestamp>({ts(0), ts(1)}), 2);
}

} // namespace facebook::velox::functions::sparksql::test

0 comments on commit 41ed291

Please sign in to comment.