From 24c903f52379f909a8507811697ad21ed1317092 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Fri, 12 Apr 2024 11:17:31 +0800 Subject: [PATCH] try --- .../expression/tests/ExpressionFuzzerTest.cpp | 3 +- .../tests/SparkExpressionFuzzerTest.cpp | 15 +++++- .../sparksql/fuzzer/AddSubtractArgGenerator.h | 47 +++++++++++++++++++ .../sparksql/fuzzer/DivideArgGenerator.h | 47 +++++++++++++++++++ .../sparksql/fuzzer/MultiplyArgGenerator.h | 45 ++++++++++++++++++ 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h create mode 100644 velox/functions/sparksql/fuzzer/DivideArgGenerator.h create mode 100644 velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h diff --git a/velox/expression/tests/ExpressionFuzzerTest.cpp b/velox/expression/tests/ExpressionFuzzerTest.cpp index b861b1b4fdf41..0b34bcb4d0fcf 100644 --- a/velox/expression/tests/ExpressionFuzzerTest.cpp +++ b/velox/expression/tests/ExpressionFuzzerTest.cpp @@ -46,6 +46,8 @@ int main(int argc, char** argv) { // experience, and initialize glog and gflags. folly::Init init(&argc, &argv); + size_t initialSeed = FLAGS_seed == 0 ? std::time(nullptr) : FLAGS_seed; + // TODO: List of the functions that at some point crash or fail and need to // be fixed before we can enable. // This list can include a mix of function names and function signatures. @@ -81,6 +83,5 @@ int main(int argc, char** argv) { {"floor", std::make_shared()}, {"round", std::make_shared()}}; - size_t initialSeed = FLAGS_seed == 0 ? std::time(nullptr) : FLAGS_seed; return FuzzerRunner::run(initialSeed, skipFunctions, {{}}, argGenerators); } diff --git a/velox/expression/tests/SparkExpressionFuzzerTest.cpp b/velox/expression/tests/SparkExpressionFuzzerTest.cpp index aac1b9e642201..7abfe9b237ca7 100644 --- a/velox/expression/tests/SparkExpressionFuzzerTest.cpp +++ b/velox/expression/tests/SparkExpressionFuzzerTest.cpp @@ -24,6 +24,12 @@ #include "velox/expression/tests/FuzzerRunner.h" #include "velox/functions/sparksql/Register.h" +#include "velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h" +#include "velox/functions/sparksql/fuzzer/DivideArgGenerator.h" +#include "velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h" + +using namespace facebook::velox::functions::sparksql::test; +using facebook::velox::test::ArgGenerator; DEFINE_int64( seed, @@ -60,5 +66,12 @@ int main(int argc, char** argv) { std::unordered_map queryConfigs = { {facebook::velox::core::QueryConfig::kSparkPartitionId, "123"}}; - return FuzzerRunner::run(FLAGS_seed, skipFunctions, queryConfigs, {}); + std::unordered_map> argGenerators = + {{"add", std::make_shared()}, + {"subtract", std::make_shared()}, + {"multiply", std::make_shared()}, + {"divide", std::make_shared()}}; + + return FuzzerRunner::run( + FLAGS_seed, skipFunctions, queryConfigs, argGenerators); } diff --git a/velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h b/velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h new file mode 100644 index 0000000000000..8793909716337 --- /dev/null +++ b/velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h @@ -0,0 +1,47 @@ +/* + * 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 "velox/expression/tests/ArgGenerator.h" +#include "velox/functions/sparksql/DecimalUtil.h" + +namespace facebook::velox::functions::sparksql::test { + +class AddSubtractArgGenerator + : public facebook::velox::test::DecimalArgGeneratorBase { + public: + AddSubtractArgGenerator() { + initialize(); + } + + protected: + std::optional> toReturnType(int count, ...) override { + VELOX_CHECK_EQ(count, 4); + va_list args; + va_start(args, count); + const int p1 = va_arg(args, int); + const int s1 = va_arg(args, int); + const int p2 = va_arg(args, int); + const int s2 = va_arg(args, int); + va_end(args); + + const auto precision = std::max(p1 - s1, p2 - s2) + std::max(s1, s2) + 1; + const auto scale = max(s1, s2); + return DecimalUtil::adjustPrecisionScale(precision, scale); + } +}; + +} // namespace facebook::velox::functions::sparksql::test diff --git a/velox/functions/sparksql/fuzzer/DivideArgGenerator.h b/velox/functions/sparksql/fuzzer/DivideArgGenerator.h new file mode 100644 index 0000000000000..350db0ed7b007 --- /dev/null +++ b/velox/functions/sparksql/fuzzer/DivideArgGenerator.h @@ -0,0 +1,47 @@ +/* + * 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 "velox/expression/tests/ArgGenerator.h" +#include "velox/functions/sparksql/DecimalUtil.h" + +namespace facebook::velox::functions::sparksql::test { + +class DivideArgGenerator + : public facebook::velox::test::DecimalArgGeneratorBase { + public: + DivideArgGenerator() { + initialize(); + } + + protected: + std::optional> toReturnType(int count, ...) override { + VELOX_CHECK_EQ(count, 4); + va_list args; + va_start(args, count); + const int p1 = va_arg(args, int); + const int s1 = va_arg(args, int); + const int p2 = va_arg(args, int); + const int s2 = va_arg(args, int); + va_end(args); + + const auto scale = std::max(6, s1 + p2 + 1); + const auto precision = p1 - s1 + s2 + scale; + return DecimalUtil::adjustPrecisionScale(precision, scale); + } +}; + +} // namespace facebook::velox::functions::sparksql::test diff --git a/velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h b/velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h new file mode 100644 index 0000000000000..f34c8ec719987 --- /dev/null +++ b/velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h @@ -0,0 +1,45 @@ +/* + * 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 "velox/expression/tests/ArgGenerator.h" +#include "velox/functions/sparksql/DecimalUtil.h" + +namespace facebook::velox::functions::sparksql::test { + +class MultiplyArgGenerator + : public facebook::velox::test::DecimalArgGeneratorBase { + public: + MultiplyArgGenerator() { + initialize(); + } + + protected: + std::optional> toReturnType(int count, ...) override { + VELOX_CHECK_EQ(count, 4); + va_list args; + va_start(args, count); + const int p1 = va_arg(args, int); + const int s1 = va_arg(args, int); + const int p2 = va_arg(args, int); + const int s2 = va_arg(args, int); + va_end(args); + + return DecimalUtil::adjustPrecisionScale(p1 + p2 + 1, s1 + s2); + } +}; + +} // namespace facebook::velox::functions::sparksql::test