-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3673e4
commit ebcb021
Showing
13 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ velox_link_libraries( | |
if(${VELOX_BUILD_TESTING}) | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
add_subdirectory(fuzzer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
velox_add_library(velox_presto_types_fuzzer TimestampWithTimeZoneFuzzer.h) | ||
|
||
velox_link_libraries(velox_presto_types_fuzzer velox_vector_fuzzer | ||
velox_presto_types velox_type_tz) |
78 changes: 78 additions & 0 deletions
78
velox/functions/prestosql/types/fuzzer/TimestampWithTimeZoneFuzzer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <boost/random/uniform_int_distribution.hpp> | ||
|
||
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" | ||
#include "velox/type/tz/TimeZoneMap.h" | ||
#include "velox/vector/fuzzer/CustomVectorFuzzer.h" | ||
|
||
namespace facebook::velox { | ||
/// A CustomVectorFuzzer for TimestampWithTimeZoneType. The millisUtc is random, | ||
/// and the time zone is selected randomly from the list of known time zones. | ||
class TimestampWithTimeZoneVectorFuzzer : public CustomVectorFuzzer { | ||
public: | ||
TimestampWithTimeZoneVectorFuzzer() | ||
: CustomVectorFuzzer(), timeZoneIds_(tz::getTimeZoneIDs()) {} | ||
|
||
const VectorPtr fuzzFlat( | ||
memory::MemoryPool* pool, | ||
const TypePtr& type, | ||
vector_size_t size, | ||
FuzzerGenerator& rng) override { | ||
VELOX_CHECK(isTimestampWithTimeZoneType(type)); | ||
|
||
auto result = BaseVector::create(type, size, pool); | ||
auto flatResult = result->asFlatVector<int64_t>(); | ||
for (auto i = 0; i < size; ++i) { | ||
int16_t timeZoneId = timeZoneIds_ | ||
[boost::random::uniform_int_distribution<size_t>()(rng) % | ||
timeZoneIds_.size()]; | ||
flatResult->set( | ||
i, | ||
pack( | ||
boost::random::uniform_int_distribution<int64_t>()(rng), | ||
timeZoneId)); | ||
} | ||
return result; | ||
} | ||
|
||
const VectorPtr fuzzConstant( | ||
memory::MemoryPool* pool, | ||
const TypePtr& type, | ||
vector_size_t size, | ||
FuzzerGenerator& rng) override { | ||
VELOX_CHECK(isTimestampWithTimeZoneType(type)); | ||
|
||
int16_t timeZoneId = timeZoneIds_ | ||
[boost::random::uniform_int_distribution<size_t>()(rng) % | ||
timeZoneIds_.size()]; | ||
|
||
return std::make_shared<ConstantVector<int64_t>>( | ||
pool, | ||
size, | ||
false, | ||
type, | ||
pack( | ||
boost::random::uniform_int_distribution<int64_t>()(rng), | ||
timeZoneId)); | ||
} | ||
|
||
private: | ||
const std::vector<int16_t> timeZoneIds_; | ||
}; | ||
} // namespace facebook::velox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "velox/vector/BaseVector.h" | ||
#include "velox/vector/fuzzer/Utils.h" | ||
|
||
namespace facebook::velox { | ||
/// An interface for fuzzing Vectors of a custom type. This is intended for use | ||
/// when a custom type does not support the full range of values of the backing | ||
/// physical type. | ||
/// | ||
/// Implementations of this interface need to be registered in an instance of | ||
/// VectorFuzzer via registerCustomVectorFuzzer in order for them to be used in | ||
/// general purpose fuzzing. | ||
class CustomVectorFuzzer { | ||
public: | ||
virtual ~CustomVectorFuzzer() = default; | ||
|
||
/// Should return a flat Vector of the given size without nulls. | ||
virtual const VectorPtr fuzzFlat( | ||
memory::MemoryPool* pool, | ||
const TypePtr& type, | ||
vector_size_t size, | ||
FuzzerGenerator& rng) = 0; | ||
|
||
/// Should return a ConstantVector of the given size backed by a single | ||
/// non-null scalar value (complex types do not need to implement this). | ||
virtual const VectorPtr fuzzConstant( | ||
memory::MemoryPool* pool, | ||
const TypePtr& type, | ||
vector_size_t size, | ||
FuzzerGenerator& rng) = 0; | ||
}; | ||
} // namespace facebook::velox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters