Skip to content

Commit

Permalink
Add ipprefix to the fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsaka committed Dec 10, 2024
1 parent 1bd480e commit c24ee31
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 22 deletions.
7 changes: 4 additions & 3 deletions velox/expression/FunctionSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "velox/expression/FunctionSignature.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>

#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 {
Expand Down Expand Up @@ -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);
}

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 @@ -125,6 +125,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 @@ -149,6 +155,7 @@ getSignaturesForCast() {
addCastFromVarcharSignature("varchar", signatures);
addCastFromDateSignature("varchar", signatures);
addCastFromTimestampSignature("varchar", signatures);
addCastFromIPPrefixSignature("varchar", signatures);

// To timestamp type.
addCastFromVarcharSignature("timestamp", signatures);
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions velox/expression/fuzzer/SparkExpressionFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/IPAddressFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/TypeOf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/aggregates/PrestoHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <xxhash.h>

#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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <gtest/gtest.h>

#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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/tests/ComparisonsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions velox/functions/prestosql/types/IPAddressType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/types/IPPrefixType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <folly/small_vector.h>

#include "velox/expression/CastExpr.h"
#include "velox/functions/prestosql/types/IPPrefixType.h"
#include "velox/functions/prestosql/types/headers/IPPrefixType.h"

namespace facebook::velox {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <folly/small_vector.h>

#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"

Expand Down Expand Up @@ -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<const IPPrefixType> IPPREFIX() {
return IPPrefixType::get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/tests/FunctionRegistryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion velox/functions/tests/RegistryTestUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit c24ee31

Please sign in to comment.