Skip to content

Commit

Permalink
feat: Add T-Digest data structure (#11665)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #11665

Add the T-Digest data structure implementation to be used in T-Digest
related functions.  Also extract the `getRandomSeed` test utility that is used
in multiple unit tests.

Reviewed By: kagamiori

Differential Revision: D66435741

fbshipit-source-id: 67b1775ad510920cb53b71950a26407fa2c64121
  • Loading branch information
Yuhta authored and facebook-github-bot committed Dec 18, 2024
1 parent 01e755c commit efbf68e
Show file tree
Hide file tree
Showing 8 changed files with 1,019 additions and 25 deletions.
9 changes: 7 additions & 2 deletions velox/common/testutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

velox_add_library(velox_test_util ScopedTestTime.cpp TestValue.cpp)
velox_link_libraries(velox_test_util PUBLIC velox_exception)
velox_add_library(velox_test_util ScopedTestTime.cpp TestValue.cpp
RandomSeed.cpp)

velox_link_libraries(
velox_test_util
PUBLIC velox_exception
PRIVATE glog::glog Folly::folly)

if(${VELOX_BUILD_TESTING})
velox_add_library(velox_test_output_matcher OutputMatcher.cpp)
Expand Down
41 changes: 41 additions & 0 deletions velox/common/testutil/RandomSeed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

#include "velox/common/testutil/RandomSeed.h"

#include <folly/Conv.h>
#include <folly/Random.h>
#include <glog/logging.h>

#include <cstdlib>

namespace facebook::velox::common::testutil {

bool useRandomSeed() {
const char* env = getenv("VELOX_TEST_USE_RANDOM_SEED");
return env && folly::to<bool>(env);
}

unsigned getRandomSeed(unsigned fixedValue) {
if (!useRandomSeed()) {
return fixedValue;
}
auto seed = folly::Random::secureRand32();
LOG(INFO) << "Random seed: " << seed;
return seed;
}

} // namespace facebook::velox::common::testutil
29 changes: 29 additions & 0 deletions velox/common/testutil/RandomSeed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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

namespace facebook::velox::common::testutil {

/// Get a truely random seed and log it for future reproducing if
/// VELOX_TEST_USE_RANDOM_SEED is set. Otherwise return a fixed value so test
/// runs are deterministic. We use environment variable because `buck test`
/// does not allow pass in command line arguments.
unsigned getRandomSeed(unsigned fixedValue);

bool useRandomSeed();

} // namespace facebook::velox::common::testutil
13 changes: 2 additions & 11 deletions velox/dwio/common/tests/utils/E2EFilterTestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "velox/common/testutil/RandomSeed.h"
#include "velox/common/time/Timer.h"
#include "velox/dwio/common/BufferedInput.h"
#include "velox/dwio/common/FileSink.h"
Expand Down Expand Up @@ -102,20 +103,10 @@ class E2EFilterTestBase : public testing::Test {
memory::MemoryManager::testingSetInstance({});
}

static bool useRandomSeed() {
// Check environment variable because `buck test` does not allow pass in
// command line arguments.
const char* env = getenv("VELOX_TEST_USE_RANDOM_SEED");
return !env ? false : folly::to<bool>(env);
}

void SetUp() override {
rootPool_ = memory::memoryManager()->addRootPool("E2EFilterTestBase");
leafPool_ = rootPool_->addLeafChild("E2EFilterTestBase");
if (useRandomSeed()) {
seed_ = folly::Random::secureRand32();
LOG(INFO) << "Random seed: " << seed_;
}
seed_ = common::testutil::getRandomSeed(seed_);
}

static bool typeKindSupportsValueHook(TypeKind kind) {
Expand Down
Loading

0 comments on commit efbf68e

Please sign in to comment.