Skip to content

Commit

Permalink
Add IPPREFIX for fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsaka committed Oct 9, 2024
1 parent 303162e commit 53f3261
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion velox/expression/FunctionSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "velox/common/base/Exceptions.h"
#include "velox/expression/FunctionSignature.h"
#include "velox/functions/prestosql/types/IPPrefixType.h"
#include "velox/type/Type.h"

namespace facebook::velox::exec {
Expand Down Expand Up @@ -120,7 +121,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);
}

Expand Down
10 changes: 10 additions & 0 deletions velox/expression/fuzzer/ExpressionFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ void addCastFromDateSignature(
signatures.push_back(makeCastSignature("date", toType));
}

void addCastFromIPPrefixSignature(
const std::string& toType,
std::vector<facebook::velox::exec::FunctionSignaturePtr>& signatures) {
signatures.push_back(makeCastSignature("ipprefix", toType));
}

std::vector<facebook::velox::exec::FunctionSignaturePtr>
getSignaturesForCast() {
std::vector<facebook::velox::exec::FunctionSignaturePtr> signatures;
Expand All @@ -146,6 +152,7 @@ getSignaturesForCast() {
addCastFromVarcharSignature("varchar", signatures);
addCastFromDateSignature("varchar", signatures);
addCastFromTimestampSignature("varchar", signatures);
addCastFromIPPrefixSignature("varchar", signatures);

// To timestamp type.
addCastFromVarcharSignature("timestamp", signatures);
Expand All @@ -155,6 +162,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();
Expand Down
4 changes: 4 additions & 0 deletions velox/functions/prestosql/types/IPPrefixType.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class IPPrefixType : public RowType {
}
};

FOLLY_ALWAYS_INLINE bool isIPPrefixName(const std::string& name) {
return (name == IPPrefixType::get()->name());
}

FOLLY_ALWAYS_INLINE bool isIPPrefixType(const TypePtr& type) {
// Pointer comparison works since this type is a singleton.
return IPPrefixType::get() == type;
Expand Down

0 comments on commit 53f3261

Please sign in to comment.