From 9265fbfd9a0716136456ef8b6e455ff110a0f7da Mon Sep 17 00:00:00 2001 From: Wei He Date: Fri, 20 Dec 2024 12:08:19 -0800 Subject: [PATCH] fix(fuzzer): Fix sanitize(type) in FuzzerUtil for IPPREFIX type (#11846) 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: https://github.com/facebookincubator/velox/pull/11846 Reviewed By: xiaoxmeng Differential Revision: D67159266 Pulled By: kagamiori fbshipit-source-id: 9a68491bdc8ab1a5fd2f3092fc3be76d944bc816 --- velox/exec/fuzzer/FuzzerUtil.cpp | 3 ++- velox/expression/fuzzer/ArgumentTypeFuzzer.cpp | 10 +++++++++- velox/expression/fuzzer/CMakeLists.txt | 1 + velox/expression/fuzzer/ExpressionFuzzer.cpp | 1 - velox/vector/fuzzer/VectorFuzzer.cpp | 9 ++++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/velox/exec/fuzzer/FuzzerUtil.cpp b/velox/exec/fuzzer/FuzzerUtil.cpp index b5fc55d92cb0..9370e2b5ab79 100644 --- a/velox/exec/fuzzer/FuzzerUtil.cpp +++ b/velox/exec/fuzzer/FuzzerUtil.cpp @@ -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; @@ -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; } diff --git a/velox/expression/fuzzer/ArgumentTypeFuzzer.cpp b/velox/expression/fuzzer/ArgumentTypeFuzzer.cpp index 4d851b313c7f..5996ffb9d2a2 100644 --- a/velox/expression/fuzzer/ArgumentTypeFuzzer.cpp +++ b/velox/expression/fuzzer/ArgumentTypeFuzzer.cpp @@ -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" @@ -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()}); } diff --git a/velox/expression/fuzzer/CMakeLists.txt b/velox/expression/fuzzer/CMakeLists.txt index 345c7e922063..6a6476e60efc 100644 --- a/velox/expression/fuzzer/CMakeLists.txt +++ b/velox/expression/fuzzer/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries( velox_type velox_expression_functions velox_fuzzer_util + velox_presto_types GTest::gtest) add_library( diff --git a/velox/expression/fuzzer/ExpressionFuzzer.cpp b/velox/expression/fuzzer/ExpressionFuzzer.cpp index 3f381b5fccac..582c8ac11b5e 100644 --- a/velox/expression/fuzzer/ExpressionFuzzer.cpp +++ b/velox/expression/fuzzer/ExpressionFuzzer.cpp @@ -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"))) { diff --git a/velox/vector/fuzzer/VectorFuzzer.cpp b/velox/vector/fuzzer/VectorFuzzer.cpp index 49750eab0d6b..24c696c943bd 100644 --- a/velox/vector/fuzzer/VectorFuzzer.cpp +++ b/velox/vector/fuzzer/VectorFuzzer.cpp @@ -22,6 +22,7 @@ #include #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" @@ -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(type), size); + } return fuzzRow(std::dynamic_pointer_cast(type), size); + } case TypeKind::ARRAY: { const auto& elementType = type->asArray().elementType();