From c24ee311a626e4b708813449959e06ffff47f828 Mon Sep 17 00:00:00 2001 From: mohsaka <135669458+mohsaka@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:43:12 -0800 Subject: [PATCH] Add ipprefix to the fuzzer --- velox/expression/FunctionSignature.cpp | 7 ++++--- velox/expression/fuzzer/ExpressionFuzzer.cpp | 10 ++++++++++ velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp | 2 ++ velox/functions/prestosql/IPAddressFunctions.h | 4 ++-- velox/functions/prestosql/TypeOf.cpp | 4 ++-- velox/functions/prestosql/aggregates/PrestoHasher.cpp | 2 +- .../prestosql/aggregates/tests/PrestoHasherTest.cpp | 2 +- .../registration/ComparisonFunctionsRegistration.cpp | 4 ++-- .../registration/GeneralFunctionsRegistration.cpp | 2 +- velox/functions/prestosql/tests/ComparisonsTest.cpp | 4 ++-- velox/functions/prestosql/types/IPAddressType.cpp | 4 ++-- velox/functions/prestosql/types/IPPrefixType.cpp | 2 +- .../prestosql/types/{ => headers}/IPAddressType.h | 0 .../prestosql/types/{ => headers}/IPPrefixType.h | 6 +++++- .../prestosql/types/tests/IPAddressTypeTest.cpp | 2 +- .../prestosql/types/tests/IPPrefixTypeTest.cpp | 2 +- velox/functions/tests/FunctionRegistryTest.cpp | 2 +- velox/functions/tests/RegistryTestUtil.h | 2 +- 18 files changed, 39 insertions(+), 22 deletions(-) rename velox/functions/prestosql/types/{ => headers}/IPAddressType.h (100%) rename velox/functions/prestosql/types/{ => headers}/IPPrefixType.h (96%) diff --git a/velox/expression/FunctionSignature.cpp b/velox/expression/FunctionSignature.cpp index a1460f1355a9..b85b9b76ce92 100644 --- a/velox/expression/FunctionSignature.cpp +++ b/velox/expression/FunctionSignature.cpp @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "velox/expression/FunctionSignature.h" #include #include - #include "velox/common/base/Exceptions.h" -#include "velox/expression/FunctionSignature.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" #include "velox/type/Type.h" namespace facebook::velox::exec { @@ -120,7 +120,8 @@ void validateBaseTypeAndCollectTypeParams( if (!isPositiveInteger(typeName) && !tryMapNameToTypeKind(typeName).has_value() && - !isDecimalName(typeName) && !isDateName(typeName)) { + !isDecimalName(typeName) && !isDateName(typeName) && + !isIPPrefixName(typeName)) { VELOX_USER_CHECK(hasType(typeName), "Type doesn't exist: '{}'", typeName); } diff --git a/velox/expression/fuzzer/ExpressionFuzzer.cpp b/velox/expression/fuzzer/ExpressionFuzzer.cpp index 876501414501..680998ce3083 100644 --- a/velox/expression/fuzzer/ExpressionFuzzer.cpp +++ b/velox/expression/fuzzer/ExpressionFuzzer.cpp @@ -125,6 +125,12 @@ void addCastFromDateSignature( signatures.push_back(makeCastSignature("date", toType)); } +void addCastFromIPPrefixSignature( + const std::string& toType, + std::vector& signatures) { + signatures.push_back(makeCastSignature("ipprefix", toType)); +} + std::vector getSignaturesForCast() { std::vector signatures; @@ -149,6 +155,7 @@ getSignaturesForCast() { addCastFromVarcharSignature("varchar", signatures); addCastFromDateSignature("varchar", signatures); addCastFromTimestampSignature("varchar", signatures); + addCastFromIPPrefixSignature("varchar", signatures); // To timestamp type. addCastFromVarcharSignature("timestamp", signatures); @@ -158,6 +165,9 @@ getSignaturesForCast() { addCastFromVarcharSignature("date", signatures); addCastFromTimestampSignature("date", signatures); + // To ipprefix type. + addCastFromVarcharSignature("ipprefix", signatures); + // For each supported translation pair T --> U, add signatures of array(T) --> // array(U), map(varchar, T) --> map(varchar, U), row(T) --> row(U). auto size = signatures.size(); diff --git a/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp b/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp index 60e1af2281ed..4174c2c174ab 100644 --- a/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp +++ b/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp @@ -71,6 +71,8 @@ int main(int argc, char** argv) { // timestamp_millis(bigint) can generate timestamps out of the supported // range that make other functions throw VeloxRuntimeErrors. "timestamp_millis(bigint) -> timestamp", + "cast(ipprefix) -> varchar", + "cast(varchar) -> ipprefix", }; // Required by spark_partition_id function. diff --git a/velox/functions/prestosql/IPAddressFunctions.h b/velox/functions/prestosql/IPAddressFunctions.h index a08ef92de534..e1537c1a3ad8 100644 --- a/velox/functions/prestosql/IPAddressFunctions.h +++ b/velox/functions/prestosql/IPAddressFunctions.h @@ -15,8 +15,8 @@ */ #pragma once -#include "velox/functions/prestosql/types/IPAddressType.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" namespace facebook::velox::functions { diff --git a/velox/functions/prestosql/TypeOf.cpp b/velox/functions/prestosql/TypeOf.cpp index f2a16af5ac2f..a8a6cadbce58 100644 --- a/velox/functions/prestosql/TypeOf.cpp +++ b/velox/functions/prestosql/TypeOf.cpp @@ -15,11 +15,11 @@ */ #include "velox/expression/VectorFunction.h" #include "velox/functions/prestosql/types/HyperLogLogType.h" -#include "velox/functions/prestosql/types/IPAddressType.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" #include "velox/functions/prestosql/types/JsonType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" #include "velox/functions/prestosql/types/UuidType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" namespace facebook::velox::functions { namespace { diff --git a/velox/functions/prestosql/aggregates/PrestoHasher.cpp b/velox/functions/prestosql/aggregates/PrestoHasher.cpp index 0df9c7756ebd..433b0670e575 100644 --- a/velox/functions/prestosql/aggregates/PrestoHasher.cpp +++ b/velox/functions/prestosql/aggregates/PrestoHasher.cpp @@ -21,8 +21,8 @@ #include #include "velox/functions/lib/RowsTranslationUtil.h" -#include "velox/functions/prestosql/types/IPAddressType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" namespace facebook::velox::aggregate { diff --git a/velox/functions/prestosql/aggregates/tests/PrestoHasherTest.cpp b/velox/functions/prestosql/aggregates/tests/PrestoHasherTest.cpp index 6b1c004b9283..4be22acdc2ca 100644 --- a/velox/functions/prestosql/aggregates/tests/PrestoHasherTest.cpp +++ b/velox/functions/prestosql/aggregates/tests/PrestoHasherTest.cpp @@ -17,8 +17,8 @@ #include #include "velox/functions/prestosql/aggregates/PrestoHasher.h" -#include "velox/functions/prestosql/types/IPAddressType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" #include "velox/type/tz/TimeZoneMap.h" #include "velox/vector/tests/utils/VectorTestBase.h" diff --git a/velox/functions/prestosql/registration/ComparisonFunctionsRegistration.cpp b/velox/functions/prestosql/registration/ComparisonFunctionsRegistration.cpp index 75b8f255719a..7798a38418eb 100644 --- a/velox/functions/prestosql/registration/ComparisonFunctionsRegistration.cpp +++ b/velox/functions/prestosql/registration/ComparisonFunctionsRegistration.cpp @@ -16,9 +16,9 @@ #include "velox/functions/Registerer.h" #include "velox/functions/lib/RegistrationHelpers.h" #include "velox/functions/prestosql/Comparisons.h" -#include "velox/functions/prestosql/types/IPAddressType.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" #include "velox/type/Type.h" namespace facebook::velox::functions { diff --git a/velox/functions/prestosql/registration/GeneralFunctionsRegistration.cpp b/velox/functions/prestosql/registration/GeneralFunctionsRegistration.cpp index a33d0a62a6bf..25ef54925c9f 100644 --- a/velox/functions/prestosql/registration/GeneralFunctionsRegistration.cpp +++ b/velox/functions/prestosql/registration/GeneralFunctionsRegistration.cpp @@ -21,8 +21,8 @@ #include "velox/functions/prestosql/GreatestLeast.h" #include "velox/functions/prestosql/InPredicate.h" #include "velox/functions/prestosql/Reduce.h" -#include "velox/functions/prestosql/types/IPAddressType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" namespace facebook::velox::functions { diff --git a/velox/functions/prestosql/tests/ComparisonsTest.cpp b/velox/functions/prestosql/tests/ComparisonsTest.cpp index 15eb7458e65d..60fd648b9f35 100644 --- a/velox/functions/prestosql/tests/ComparisonsTest.cpp +++ b/velox/functions/prestosql/tests/ComparisonsTest.cpp @@ -19,9 +19,9 @@ #include "velox/functions/Udf.h" #include "velox/functions/lib/RegistrationHelpers.h" #include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h" -#include "velox/functions/prestosql/types/IPAddressType.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" #include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" #include "velox/type/tests/utils/CustomTypesForTesting.h" #include "velox/type/tz/TimeZoneMap.h" diff --git a/velox/functions/prestosql/types/IPAddressType.cpp b/velox/functions/prestosql/types/IPAddressType.cpp index 1b47fd3cc005..44349b7b4085 100644 --- a/velox/functions/prestosql/types/IPAddressType.cpp +++ b/velox/functions/prestosql/types/IPAddressType.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "velox/functions/prestosql/types/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" #include "velox/expression/CastExpr.h" #include "velox/expression/VectorWriters.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" namespace facebook::velox { diff --git a/velox/functions/prestosql/types/IPPrefixType.cpp b/velox/functions/prestosql/types/IPPrefixType.cpp index 8963044f5a63..30fbe07f58a6 100644 --- a/velox/functions/prestosql/types/IPPrefixType.cpp +++ b/velox/functions/prestosql/types/IPPrefixType.cpp @@ -16,7 +16,7 @@ #include #include "velox/expression/CastExpr.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" namespace facebook::velox { diff --git a/velox/functions/prestosql/types/IPAddressType.h b/velox/functions/prestosql/types/headers/IPAddressType.h similarity index 100% rename from velox/functions/prestosql/types/IPAddressType.h rename to velox/functions/prestosql/types/headers/IPAddressType.h diff --git a/velox/functions/prestosql/types/IPPrefixType.h b/velox/functions/prestosql/types/headers/IPPrefixType.h similarity index 96% rename from velox/functions/prestosql/types/IPPrefixType.h rename to velox/functions/prestosql/types/headers/IPPrefixType.h index d345e1c17af4..31e130bc0776 100644 --- a/velox/functions/prestosql/types/IPPrefixType.h +++ b/velox/functions/prestosql/types/headers/IPPrefixType.h @@ -18,7 +18,7 @@ #include #include "velox/common/base/Status.h" -#include "velox/functions/prestosql/types/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" #include "velox/type/SimpleFunctionApi.h" #include "velox/type/Type.h" @@ -139,6 +139,10 @@ FOLLY_ALWAYS_INLINE bool isIPPrefixType(const TypePtr& type) { return IPPrefixType::get() == type; } +FOLLY_ALWAYS_INLINE bool isIPPrefixName(const std::string& name) { + return (name == IPPrefixType::get()->name()); +} + FOLLY_ALWAYS_INLINE std::shared_ptr IPPREFIX() { return IPPrefixType::get(); } diff --git a/velox/functions/prestosql/types/tests/IPAddressTypeTest.cpp b/velox/functions/prestosql/types/tests/IPAddressTypeTest.cpp index f65691e1c05f..b0de1bd9567d 100644 --- a/velox/functions/prestosql/types/tests/IPAddressTypeTest.cpp +++ b/velox/functions/prestosql/types/tests/IPAddressTypeTest.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "velox/functions/prestosql/types/IPAddressType.h" +#include "velox/functions/prestosql/types/headers/IPAddressType.h" #include "velox/functions/prestosql/types/tests/TypeTestBase.h" namespace facebook::velox::test { diff --git a/velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp b/velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp index 12873470cdac..4b3b5058dc6e 100644 --- a/velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp +++ b/velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" #include "velox/functions/prestosql/types/tests/TypeTestBase.h" namespace facebook::velox::test { diff --git a/velox/functions/tests/FunctionRegistryTest.cpp b/velox/functions/tests/FunctionRegistryTest.cpp index 0523af23a5db..c85a2db0ef37 100644 --- a/velox/functions/tests/FunctionRegistryTest.cpp +++ b/velox/functions/tests/FunctionRegistryTest.cpp @@ -26,7 +26,7 @@ #include "velox/functions/Registerer.h" #include "velox/functions/prestosql/registration/RegistrationFunctions.h" #include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" #include "velox/functions/tests/RegistryTestUtil.h" #include "velox/type/Type.h" diff --git a/velox/functions/tests/RegistryTestUtil.h b/velox/functions/tests/RegistryTestUtil.h index 4f1132ede02b..b0753e8bf7c2 100644 --- a/velox/functions/tests/RegistryTestUtil.h +++ b/velox/functions/tests/RegistryTestUtil.h @@ -18,7 +18,7 @@ #include "velox/expression/FunctionSignature.h" #include "velox/expression/VectorFunction.h" #include "velox/functions/Macros.h" -#include "velox/functions/prestosql/types/IPPrefixType.h" +#include "velox/functions/prestosql/types/headers/IPPrefixType.h" namespace facebook::velox {