Skip to content

Commit

Permalink
Extract the definition of Vector::Options::TimestampPrecision to Util.h
Browse files Browse the repository at this point in the history
Differential Revision: D65576378
  • Loading branch information
kagamiori authored and facebook-github-bot committed Nov 15, 2024
1 parent 3eb2fa4 commit de89b8f
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 69 deletions.
6 changes: 3 additions & 3 deletions velox/exec/fuzzer/AggregationFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AggregationFuzzer : public AggregationFuzzerBase {
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
customInputGenerators,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down Expand Up @@ -214,7 +214,7 @@ void aggregateFuzzer(
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
customInputGenerators,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down Expand Up @@ -245,7 +245,7 @@ AggregationFuzzer::AggregationFuzzer(
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
customInputGenerators,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down
2 changes: 1 addition & 1 deletion velox/exec/fuzzer/AggregationFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void aggregateFuzzer(
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
customInputGenerators,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down
4 changes: 2 additions & 2 deletions velox/exec/fuzzer/AggregationFuzzerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AggregationFuzzerBase {
customVerificationFunctions,
const std::unordered_map<std::string, std::shared_ptr<InputGenerator>>&
customInputGenerators,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down Expand Up @@ -151,7 +151,7 @@ class AggregationFuzzerBase {
PlanWithSplits deserialize(const folly::dynamic& obj);

static VectorFuzzer::Options getFuzzerOptions(
VectorFuzzer::Options::TimestampPrecision timestampPrecision) {
FuzzerTimestampPrecision timestampPrecision) {
VectorFuzzer::Options opts;
opts.vectorSize = FLAGS_batch_size;
opts.stringVariableLength = true;
Expand Down
4 changes: 2 additions & 2 deletions velox/exec/fuzzer/AggregationFuzzerOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ struct AggregationFuzzerOptions {
std::unordered_set<std::string> orderDependentFunctions;

/// Timestamp precision to use when generating inputs of type TIMESTAMP.
VectorFuzzer::Options::TimestampPrecision timestampPrecision{
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds};
FuzzerTimestampPrecision timestampPrecision{
FuzzerTimestampPrecision::kMilliSeconds};

/// A set of configuration properties to use when running query plans.
/// Could be used to specify timezone or enable/disable settings that
Expand Down
3 changes: 1 addition & 2 deletions velox/exec/fuzzer/JoinFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class JoinFuzzer {
opts.stringVariableLength = true;
opts.stringLength = 100;
opts.nullRatio = FLAGS_null_ratio;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
return opts;
}

Expand Down
2 changes: 1 addition & 1 deletion velox/exec/fuzzer/WindowFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ void windowFuzzer(
customInputGenerators,
const std::unordered_set<std::string>& orderDependentFunctions,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down
4 changes: 2 additions & 2 deletions velox/exec/fuzzer/WindowFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WindowFuzzer : public AggregationFuzzerBase {
customInputGenerators,
const std::unordered_set<std::string>& orderDependentFunctions,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down Expand Up @@ -243,7 +243,7 @@ void windowFuzzer(
customInputGenerators,
const std::unordered_set<std::string>& orderDependentFunctions,
const std::unordered_map<std::string, DataSpec>& functionDataSpec,
VectorFuzzer::Options::TimestampPrecision timestampPrecision,
FuzzerTimestampPrecision timestampPrecision,
const std::unordered_map<std::string, std::string>& queryConfigs,
const std::unordered_map<std::string, std::string>& hiveConfigs,
bool orderableGroupKeys,
Expand Down
3 changes: 1 addition & 2 deletions velox/exec/fuzzer/WriterFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class WriterFuzzer {
opts.vectorSize = FLAGS_batch_size;
opts.stringLength = 10;
opts.nullRatio = FLAGS_null_ratio;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
return opts;
}

Expand Down
2 changes: 1 addition & 1 deletion velox/exec/tests/ExchangeFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class ExchangeFuzzer : public VectorTestBase {
options_.maxConstantContainerSize = 2;
options_.normalizeMapKeys = fuzzer_.coinToss(0.95);
options_.timestampPrecision =
static_cast<VectorFuzzer::Options::TimestampPrecision>(randInt(0, 3));
static_cast<FuzzerTimestampPrecision>(randInt(0, 3));
options_.allowLazyVector = false;

fuzzer_.setOptions(options_);
Expand Down
3 changes: 1 addition & 2 deletions velox/expression/fuzzer/FuzzerRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ VectorFuzzer::Options getVectorFuzzerOptions() {
opts.stringVariableLength = true;
opts.stringLength = 100;
opts.nullRatio = FLAGS_null_ratio;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
return opts;
}

Expand Down
3 changes: 1 addition & 2 deletions velox/functions/lib/window/tests/WindowTestBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ VectorPtr WindowTestBase::makeRandomInputVector(
VectorFuzzer::Options options;
options.vectorSize = size;
options.nullRatio = nullRatio;
options.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds;
options.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds;
VectorFuzzer fuzzer(options, pool_.get(), 0);
return fuzzer.fuzzFlat(type);
}
Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/fuzzer/AggregationFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char** argv) {
options.customInputGenerators =
facebook::velox::exec::test::getCustomInputGenerators();
options.timestampPrecision =
facebook::velox::VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
facebook::velox::FuzzerTimestampPrecision::kMilliSeconds;
std::shared_ptr<facebook::velox::memory::MemoryPool> rootPool{
facebook::velox::memory::memoryManager()->addRootPool()};

Expand Down
2 changes: 1 addition & 1 deletion velox/functions/prestosql/fuzzer/WindowFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int argc, char** argv) {
facebook::velox::exec::test::getCustomInputGenerators();
options.orderDependentFunctions = orderDependentFunctions;
options.timestampPrecision =
facebook::velox::VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
facebook::velox::FuzzerTimestampPrecision::kMilliSeconds;
std::shared_ptr<facebook::velox::memory::MemoryPool> rootPool{
facebook::velox::memory::memoryManager()->addRootPool()};
return Runner::run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class BenchmarkHelper {
opts.stringVariableLength = true;
opts.stringLength = 20;
// Spark uses microseconds to store timestamp
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds;

auto seed = folly::Random::rand32();
VectorFuzzer fuzzer(opts, pool_.get(), seed);
Expand Down
3 changes: 1 addition & 2 deletions velox/row/tests/CompactRowTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ TEST_F(CompactRowTest, fuzz) {
opts.complexElementsMaxSize = 1'000;

// Spark uses microseconds to store timestamp
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds;

VectorFuzzer fuzzer(opts, pool_.get());

Expand Down
3 changes: 1 addition & 2 deletions velox/row/tests/UnsafeRowFuzzTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class UnsafeRowFuzzTests : public ::testing::Test {
opts.complexElementsMaxSize = 10'000;

// Spark uses microseconds to store timestamp
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds,
opts.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds,
opts.containerLength = 10;

VectorFuzzer fuzzer(opts, pool_.get());
Expand Down
3 changes: 1 addition & 2 deletions velox/serializers/tests/CompactRowSerializerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ TEST_P(CompactRowSerializerTest, fuzz) {
opts.containerVariableLength = false;

// Spark uses microseconds to store timestamp
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds;
opts.containerLength = 10;

const auto seed = folly::Random::rand32();
Expand Down
23 changes: 8 additions & 15 deletions velox/serializers/tests/PrestoSerializerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class PrestoSerializerTest
options.normalizeMapKeys = randInt(0, 20) < 16;
if (isFirst) {
options.timestampPrecision =
static_cast<VectorFuzzer::Options::TimestampPrecision>(randInt(0, 3));
static_cast<FuzzerTimestampPrecision>(randInt(0, 3));
}
options.allowLazyVector = false;
}
Expand Down Expand Up @@ -1291,8 +1291,7 @@ TEST_P(PrestoSerializerTest, lazy) {

TEST_P(PrestoSerializerTest, ioBufRoundTrip) {
VectorFuzzer::Options opts;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
opts.nullRatio = 0.1;
VectorFuzzer fuzzer(opts, pool_.get());

Expand All @@ -1310,13 +1309,11 @@ TEST_P(PrestoSerializerTest, ioBufRoundTrip) {

TEST_P(PrestoSerializerTest, roundTrip) {
VectorFuzzer::Options opts;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
opts.nullRatio = 0.1;
VectorFuzzer fuzzer(opts, pool_.get());
VectorFuzzer::Options nonNullOpts;
nonNullOpts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
nonNullOpts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
nonNullOpts.nullRatio = 0;
VectorFuzzer nonNullFuzzer(nonNullOpts, pool_.get());

Expand All @@ -1335,8 +1332,7 @@ TEST_P(PrestoSerializerTest, roundTrip) {

TEST_P(PrestoSerializerTest, encodedRoundtrip) {
VectorFuzzer::Options opts;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
opts.nullRatio = 0.1;
opts.dictionaryHasNulls = false;
VectorFuzzer fuzzer(opts, pool_.get());
Expand Down Expand Up @@ -1474,13 +1470,11 @@ TEST_P(PrestoSerializerTest, typeMismatch) {

TEST_P(PrestoSerializerTest, lexer) {
VectorFuzzer::Options opts;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
opts.nullRatio = 0.1;
VectorFuzzer fuzzer(opts, pool_.get());
VectorFuzzer::Options nonNullOpts;
nonNullOpts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
nonNullOpts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
nonNullOpts.nullRatio = 0;
VectorFuzzer nonNullFuzzer(nonNullOpts, pool_.get());

Expand Down Expand Up @@ -1609,8 +1603,7 @@ TEST_F(PrestoSerializerTest, serdeSingleColumn) {
opts.stringVariableLength = true;
opts.stringLength = 20;
opts.containerVariableLength = false;
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMilliSeconds;
opts.containerLength = 10;

auto seed = 0;
Expand Down
3 changes: 1 addition & 2 deletions velox/serializers/tests/UnsafeRowSerializerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ TEST_P(UnsafeRowSerializerTest, types) {
opts.containerVariableLength = false;

// Spark uses microseconds to store timestamp
opts.timestampPrecision =
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds;
opts.timestampPrecision = FuzzerTimestampPrecision::kMicroSeconds;
opts.containerLength = 10;

auto seed = folly::Random::rand32();
Expand Down
7 changes: 7 additions & 0 deletions velox/vector/fuzzer/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace facebook::velox {

using FuzzerGenerator = std::mt19937;

enum class FuzzerTimestampPrecision : int8_t {
kNanoSeconds = 0,
kMicroSeconds = 1,
kMilliSeconds = 2,
kSeconds = 3,
};

namespace generator_spec_utils {

bool coinToss(FuzzerGenerator& rng, double threshold);
Expand Down
8 changes: 4 additions & 4 deletions velox/vector/fuzzer/VectorFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ Timestamp randTimestamp(FuzzerGenerator& rng, VectorFuzzer::Options opts) {
constexpr int64_t millisInSecond = 1'000;

switch (opts.timestampPrecision) {
case VectorFuzzer::Options::TimestampPrecision::kNanoSeconds:
case FuzzerTimestampPrecision::kNanoSeconds:
return Timestamp(
rand<int64_t>(rng, min, max), (rand<int64_t>(rng) % MAX_NANOS));
case VectorFuzzer::Options::TimestampPrecision::kMicroSeconds:
case FuzzerTimestampPrecision::kMicroSeconds:
return Timestamp::fromMicros(
rand<int64_t>(rng, min, max) * microInSecond +
rand<int64_t>(rng, -microInSecond, microInSecond));
case VectorFuzzer::Options::TimestampPrecision::kMilliSeconds:
case FuzzerTimestampPrecision::kMilliSeconds:
return Timestamp::fromMillis(
rand<int64_t>(rng, min, max) * millisInSecond +
rand<int64_t>(rng, -millisInSecond, millisInSecond));
case VectorFuzzer::Options::TimestampPrecision::kSeconds:
case FuzzerTimestampPrecision::kSeconds:
return Timestamp(rand<int64_t>(rng, min, max), 0);
}
return {}; // no-op.
Expand Down
10 changes: 3 additions & 7 deletions velox/vector/fuzzer/VectorFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "velox/vector/BaseVector.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/fuzzer/GeneratorSpec.h"
#include "velox/vector/fuzzer/Utils.h"

namespace facebook::velox {

Expand Down Expand Up @@ -140,13 +141,8 @@ class VectorFuzzer {

/// Control the precision of timestamps generated. By default generate using
/// nanoseconds precision.
enum class TimestampPrecision : int8_t {
kNanoSeconds = 0,
kMicroSeconds = 1,
kMilliSeconds = 2,
kSeconds = 3,
};
TimestampPrecision timestampPrecision{TimestampPrecision::kNanoSeconds};
FuzzerTimestampPrecision timestampPrecision{
FuzzerTimestampPrecision::kNanoSeconds};

/// If true, fuzz() will randomly generate lazy vectors and fuzzInputRow()
/// will generate a raw vector with children that can randomly be lazy
Expand Down
16 changes: 5 additions & 11 deletions velox/vector/fuzzer/tests/VectorFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ TEST_F(VectorFuzzerTest, containerHasNulls) {
}

FlatVectorPtr<Timestamp> genTimestampVector(
VectorFuzzer::Options::TimestampPrecision precision,
FuzzerTimestampPrecision precision,
size_t vectorSize,
memory::MemoryPool* pool) {
VectorFuzzer::Options opts;
Expand All @@ -598,7 +598,7 @@ TEST_F(VectorFuzzerTest, timestamp) {

// Second granularity.
auto secTsVector = genTimestampVector(
VectorFuzzer::Options::TimestampPrecision::kSeconds, vectorSize, pool());
FuzzerTimestampPrecision::kSeconds, vectorSize, pool());

for (size_t i = 0; i < vectorSize; ++i) {
auto ts = secTsVector->valueAt(i);
Expand All @@ -607,9 +607,7 @@ TEST_F(VectorFuzzerTest, timestamp) {

// Millisecond granularity.
auto milliTsVector = genTimestampVector(
VectorFuzzer::Options::TimestampPrecision::kMilliSeconds,
vectorSize,
pool());
FuzzerTimestampPrecision::kMilliSeconds, vectorSize, pool());

for (size_t i = 0; i < vectorSize; ++i) {
auto ts = milliTsVector->valueAt(i);
Expand All @@ -618,9 +616,7 @@ TEST_F(VectorFuzzerTest, timestamp) {

// Microsecond granularity.
auto microTsVector = genTimestampVector(
VectorFuzzer::Options::TimestampPrecision::kMicroSeconds,
vectorSize,
pool());
FuzzerTimestampPrecision::kMicroSeconds, vectorSize, pool());

for (size_t i = 0; i < vectorSize; ++i) {
auto ts = microTsVector->valueAt(i);
Expand All @@ -629,9 +625,7 @@ TEST_F(VectorFuzzerTest, timestamp) {

// Nanosecond granularity.
auto nanoTsVector = genTimestampVector(
VectorFuzzer::Options::TimestampPrecision::kNanoSeconds,
vectorSize,
pool());
FuzzerTimestampPrecision::kNanoSeconds, vectorSize, pool());

// Check that at least one timestamp has nano > 0.
bool nanosFound = false;
Expand Down

0 comments on commit de89b8f

Please sign in to comment.