diff --git a/velox/expression/FunctionSignature.cpp b/velox/expression/FunctionSignature.cpp index a1460f1355a94..d8c7f723ab024 100644 --- a/velox/expression/FunctionSignature.cpp +++ b/velox/expression/FunctionSignature.cpp @@ -20,6 +20,8 @@ #include "velox/expression/FunctionSignature.h" #include "velox/type/Type.h" +constexpr folly::StringPiece ipPrefixTypeName{"IPPREFIX"}; + namespace facebook::velox::exec { std::string sanitizeName(const std::string& name) { @@ -120,7 +122,8 @@ void validateBaseTypeAndCollectTypeParams( if (!isPositiveInteger(typeName) && !tryMapNameToTypeKind(typeName).has_value() && - !isDecimalName(typeName) && !isDateName(typeName)) { + !isDecimalName(typeName) && !isDateName(typeName) && + !(ipPrefixTypeName == 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 fae7b0902036e..680998ce3083b 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(); @@ -664,6 +674,7 @@ bool ExpressionFuzzer::isSupportedSignature( if (usesTypeName(signature, "opaque") || usesTypeName(signature, "timestamp with time zone") || usesTypeName(signature, "interval day to second") || + usesTypeName(signature, "ipprefix") || (!options_.enableDecimalType && usesTypeName(signature, "decimal")) || (!options_.enableComplexTypes && useComplexType) || (options_.enableComplexTypes && usesTypeName(signature, "unknown"))) { diff --git a/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp b/velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp index 60e1af2281edc..4174c2c174abe 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.