Skip to content

Commit

Permalink
fix(fuzzer): Fix sanitize(type) in FuzzerUtil for IPPREFIX type (#11846)
Browse files Browse the repository at this point in the history
Summary:
The sanitize(type) method incorrectly converts the IPPrefixType into a RowType, which cause error during expression compilation of a fuzzer run. Since IPPrefixType already has field names, there is no need to sanitize it. This diff makes sanitize(type) skip sanitizing IPPrefixType.

Pull Request resolved: #11846

Reviewed By: xiaoxmeng

Differential Revision: D67159266

Pulled By: kagamiori

fbshipit-source-id: 9a68491bdc8ab1a5fd2f3092fc3be76d944bc816
  • Loading branch information
kagamiori authored and facebook-github-bot committed Dec 20, 2024
1 parent c519980 commit 9265fbf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion velox/exec/fuzzer/FuzzerUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "velox/dwio/catalog/fbhive/FileUtils.h"
#include "velox/dwio/dwrf/writer/Writer.h"
#include "velox/expression/SignatureBinder.h"
#include "velox/functions/prestosql/types/IPPrefixType.h"

using namespace facebook::velox::dwio::catalog::fbhive;

Expand Down Expand Up @@ -283,7 +284,7 @@ bool usesTypeName(
// If 'type' is a RowType or contains RowTypes with empty field names, adds
// default names to these fields in the RowTypes.
TypePtr sanitize(const TypePtr& type) {
if (!type) {
if (!type || isIPPrefixType(type)) {
return type;
}

Expand Down
10 changes: 9 additions & 1 deletion velox/expression/fuzzer/ArgumentTypeFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

#include "velox/exec/fuzzer/FuzzerUtil.h"
#include "velox/expression/ReverseSignatureBinder.h"
#include "velox/expression/SignatureBinder.h"
#include "velox/functions/prestosql/types/IPAddressType.h"
#include "velox/functions/prestosql/types/IPPrefixType.h"
#include "velox/functions/prestosql/types/JsonType.h"
#include "velox/type/Type.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

Expand All @@ -32,6 +34,12 @@ using exec::test::sanitizeTryResolveType;
std::string typeToBaseName(const TypePtr& type) {
if (type->isDecimal()) {
return "decimal";
} else if (isIPPrefixType(type)) {
return "ipprefix";
} else if (isIPAddressType(type)) {
return "ipaddress";
} else if (isJsonType(type)) {
return "json";
}
return boost::algorithm::to_lower_copy(std::string{type->kindName()});
}
Expand Down
1 change: 1 addition & 0 deletions velox/expression/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target_link_libraries(
velox_type
velox_expression_functions
velox_fuzzer_util
velox_presto_types
GTest::gtest)

add_library(
Expand Down
1 change: 0 additions & 1 deletion velox/expression/fuzzer/ExpressionFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ 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"))) {
Expand Down
9 changes: 8 additions & 1 deletion velox/vector/fuzzer/VectorFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <locale>

#include "velox/common/base/Exceptions.h"
#include "velox/functions/prestosql/types/IPPrefixType.h"
#include "velox/type/Timestamp.h"
#include "velox/vector/BaseVector.h"
#include "velox/vector/FlatVector.h"
Expand Down Expand Up @@ -605,8 +606,14 @@ VectorPtr VectorFuzzer::fuzzComplex(const TypePtr& type, vector_size_t size) {
opts_.allowLazyVector = false;

switch (type->kind()) {
case TypeKind::ROW:
case TypeKind::ROW: {
if (isIPPrefixType(type)) {
ScopedOptions restorer(this);
opts_.containerHasNulls = false;
return fuzzRow(std::dynamic_pointer_cast<const RowType>(type), size);
}
return fuzzRow(std::dynamic_pointer_cast<const RowType>(type), size);
}

case TypeKind::ARRAY: {
const auto& elementType = type->asArray().elementType();
Expand Down

0 comments on commit 9265fbf

Please sign in to comment.