Skip to content

Commit 4fdec14

Browse files
committed
Merge branch 'main' into checked-decimal-multiply
Resolve conflicts with merged checked_add/checked_subtract (PR facebookincubator#16302). Update multiply tests to use generic checkedDecimalArithmetic helpers.
2 parents 4242b31 + 8853645 commit 4fdec14

File tree

263 files changed

+11208
-2857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+11208
-2857
lines changed

.github/workflows/claude-review.yml

Lines changed: 172 additions & 46 deletions
Large diffs are not rendered by default.

.github/workflows/docs.yml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ concurrency:
3535
jobs:
3636
build_docs:
3737
name: Build and Push
38-
runs-on: 8-core-ubuntu
38+
runs-on: 16-core-ubuntu
3939
container: ghcr.io/facebookincubator/velox-dev:centos9
4040
env:
4141
CCACHE_DIR: /tmp/ccache
@@ -48,25 +48,71 @@ jobs:
4848
id: restore-cache
4949
with:
5050
path: ${{ env.CCACHE_DIR }}
51-
key: ccache-docs-8-core-ubuntu
51+
key: ccache-docs-16-core-ubuntu
5252

5353
- name: Checkout
5454
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5555
with:
5656
fetch-depth: 0
5757
persist-credentials: true
5858

59+
- name: Configure git safe directory
60+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
61+
5962
- name: Install System Dependencies
6063
run: |
6164
dnf install -y --setopt=install_weak_deps=False pandoc
6265
6366
- name: CCache Stats Before
6467
run: ccache -sz
6568

69+
- name: Install uv
70+
run: |
71+
pip install --upgrade uv
72+
uv --version
73+
74+
- name: Check for pyvelox changes
75+
id: check-pyvelox
76+
run: |
77+
if [ "${{ github.event_name }}" = "pull_request" ]; then
78+
CHANGED=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..HEAD)
79+
else
80+
CHANGED=$(git diff --name-only HEAD~1..HEAD)
81+
fi
82+
if echo "$CHANGED" | grep -qE '^(python/|velox/python/)'; then
83+
echo "Building pyvelox: python/ files changed."
84+
echo "changed=true" >> $GITHUB_OUTPUT
85+
else
86+
echo "Skipping pyvelox build: no python/ files changed."
87+
echo "changed=false" >> $GITHUB_OUTPUT
88+
fi
89+
6690
- name: Install Python Dependencies
91+
timeout-minutes: 30
92+
env:
93+
PYVELOX_CHANGED: ${{ steps.check-pyvelox.outputs.changed }}
6794
run: |
68-
# Install pyvelox to generate it's docs
69-
uv sync --extra docs
95+
# When python/ files haven't changed, skip building pyvelox
96+
# from C++ source (slow) and only install doc dependencies.
97+
EXTRA_FLAGS=""
98+
if [ "$PYVELOX_CHANGED" != "true" ]; then
99+
echo "Skipping pyvelox C++ build (no changes in python/)."
100+
EXTRA_FLAGS="--no-install-project"
101+
fi
102+
# Retry up to 3 times to handle transient network issues
103+
# (pip/uv hangs, registry timeouts).
104+
for attempt in 1 2 3; do
105+
echo "Attempt $attempt of 3..."
106+
if uv sync --extra docs $EXTRA_FLAGS --verbose; then
107+
echo "Python dependencies installed successfully."
108+
exit 0
109+
fi
110+
echo "Attempt $attempt failed. Cleaning up and retrying in 10 seconds..."
111+
rm -rf .venv uv.lock
112+
sleep 10
113+
done
114+
echo "All 3 attempts failed."
115+
exit 1
70116
71117
- name: CCache Stats After
72118
run: ccache -s
@@ -75,7 +121,7 @@ jobs:
75121
uses: apache/infrastructure-actions/stash/save@3354c1565d4b0e335b78a76aedd82153a9e144d4
76122
with:
77123
path: ${{ env.CCACHE_DIR }}
78-
key: ccache-docs-8-core-ubuntu
124+
key: ccache-docs-16-core-ubuntu
79125

80126
- name: Build Documentation
81127
run: |
@@ -92,7 +138,6 @@ jobs:
92138
run: |
93139
git config --global user.email "velox@users.noreply.github.com"
94140
git config --global user.name "velox"
95-
git config --global --add safe.directory ${GITHUB_WORKSPACE}
96141
97142
- name: Push Documentation
98143
if: ${{ github.event_name == 'push' && github.repository == 'facebookincubator/velox'}}

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
670670
# Find Threads library
671671
find_package(Threads REQUIRED)
672672
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fcoroutines>)
673+
# Explicitly enable folly coroutines when compiler supports them.
674+
# This is required for folly::coro::AsyncGenerator to work correctly.
675+
add_compile_definitions(FOLLY_HAS_COROUTINES=1)
673676
endif()
674677

675678
if(VELOX_BUILD_TESTING AND NOT VELOX_ENABLE_DUCKDB)

velox/benchmarks/basic/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ target_link_libraries(
107107
add_executable(velox_cast_benchmark CastBenchmark.cpp)
108108
target_link_libraries(velox_cast_benchmark ${velox_benchmark_deps} velox_vector_test_lib)
109109

110+
add_executable(velox_benchmark_expr_flat_no_nulls ExprFlatNoNullsBenchmark.cpp)
111+
target_link_libraries(
112+
velox_benchmark_expr_flat_no_nulls
113+
${velox_benchmark_deps}
114+
velox_functions_prestosql
115+
)
116+
110117
add_executable(velox_format_datetime_benchmark FormatDateTimeBenchmark.cpp)
111118
target_link_libraries(
112119
velox_format_datetime_benchmark
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/// Benchmark comparing expression evaluation with FlatNoNulls fast path
18+
/// enabled vs disabled via the expression.eval_flat_no_nulls config.
19+
20+
#include <folly/Benchmark.h>
21+
#include <folly/init/Init.h>
22+
23+
#include "velox/benchmarks/ExpressionBenchmarkBuilder.h"
24+
#include "velox/core/QueryConfig.h"
25+
#include "velox/functions/prestosql/registration/RegistrationFunctions.h"
26+
27+
using namespace facebook;
28+
using namespace facebook::velox;
29+
30+
namespace {
31+
32+
void addArithmeticBenchmarks(
33+
ExpressionBenchmarkBuilder& builder,
34+
const std::string& prefix) {
35+
for (auto vectorSize : {1'024, 4'096, 40'960, 99'999}) {
36+
builder
37+
.addBenchmarkSet(
38+
fmt::format("{}_arith_batch{}", prefix, vectorSize),
39+
ROW({"a", "b", "c", "d"}, {DOUBLE(), DOUBLE(), DOUBLE(), DOUBLE()}))
40+
.withFuzzerOptions(
41+
{.vectorSize = static_cast<size_t>(vectorSize), .nullRatio = 0.0})
42+
// Simple arithmetic — 1 node.
43+
.addExpression("add_ab", "a + b")
44+
// Complex arithmetic — 7 nodes.
45+
.addExpression("complex_7n", "(a + b) * c + (a - d) * b")
46+
// Deep tree — 15 nodes, depth 8 (left-skewed chain).
47+
.addExpression(
48+
"deep_15n_d8", "((((((a + b) * c - d) + a) * b - c) + d) * a - b)")
49+
.withIterations(1'000);
50+
}
51+
}
52+
53+
void addComparisonBenchmarks(
54+
ExpressionBenchmarkBuilder& builder,
55+
const std::string& prefix) {
56+
for (auto vectorSize : {1'024, 4'096, 40'960, 99'999}) {
57+
builder
58+
.addBenchmarkSet(
59+
fmt::format("{}_cmp_batch{}", prefix, vectorSize),
60+
ROW({"a", "b"}, {DOUBLE(), DOUBLE()}))
61+
.withFuzzerOptions(
62+
{.vectorSize = static_cast<size_t>(vectorSize), .nullRatio = 0.0})
63+
// Comparison — 1 node.
64+
.addExpression("eq_ab", "a = b")
65+
.withIterations(1'000);
66+
}
67+
}
68+
69+
void addConstMixedBenchmarks(
70+
ExpressionBenchmarkBuilder& builder,
71+
const std::string& prefix) {
72+
for (auto vectorSize : {1'024, 4'096, 40'960, 99'999}) {
73+
builder
74+
.addBenchmarkSet(
75+
fmt::format("{}_const_batch{}", prefix, vectorSize),
76+
ROW({"a", "b"}, {DOUBLE(), DOUBLE()}))
77+
.withFuzzerOptions(
78+
{.vectorSize = static_cast<size_t>(vectorSize), .nullRatio = 0.0})
79+
// 1 constant.
80+
.addExpression("const_1", "a + 1.5")
81+
// 2 constants.
82+
.addExpression("const_2", "(a + 1.5) * 2.0")
83+
// 3 constants mixed with columns — 7 nodes.
84+
.addExpression("const_3_7n", "(a + 1.5) * 2.0 + (a - 3.0) * b")
85+
.withIterations(1'000);
86+
}
87+
}
88+
89+
/// Extends ExpressionBenchmarkBuilder to allow setting query config.
90+
class ConfigurableBenchmarkBuilder : public ExpressionBenchmarkBuilder {
91+
public:
92+
void setConfig(const std::string& key, const std::string& value) {
93+
queryCtx_->testingOverrideConfigUnsafe({{key, value}});
94+
}
95+
};
96+
97+
} // namespace
98+
99+
int main(int argc, char** argv) {
100+
folly::Init init(&argc, &argv);
101+
memory::MemoryManager::initialize(memory::MemoryManager::Options{});
102+
functions::prestosql::registerAllScalarFunctions();
103+
104+
// Fast path ON (default).
105+
ConfigurableBenchmarkBuilder fastPathOn;
106+
addArithmeticBenchmarks(fastPathOn, "on");
107+
addComparisonBenchmarks(fastPathOn, "on");
108+
addConstMixedBenchmarks(fastPathOn, "on");
109+
110+
// Fast path OFF via config.
111+
ConfigurableBenchmarkBuilder fastPathOff;
112+
fastPathOff.setConfig(core::QueryConfig::kExprEvalFlatNoNulls, "false");
113+
addArithmeticBenchmarks(fastPathOff, "off");
114+
addComparisonBenchmarks(fastPathOff, "off");
115+
addConstMixedBenchmarks(fastPathOff, "off");
116+
117+
fastPathOn.registerBenchmarks();
118+
fastPathOff.registerBenchmarks();
119+
folly::runBenchmarks();
120+
return 0;
121+
}

velox/common/base/BloomFilter.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ class BloomFilter {
110110
}
111111
}
112112

113+
/// Computes m (total bits of Bloom filter) which is expected to achieve,
114+
/// for the specified expected insertions, the required false positive
115+
/// probability.
116+
///
117+
/// See
118+
/// http://en.wikipedia.org/wiki/Bloom_filter#Probability_of_false_positives
119+
/// for the formula.
120+
///
121+
/// @param n expected insertions (must be positive).
122+
/// @param p false positive rate (must be 0 < p < 1).
123+
static int64_t optimalNumOfBits(int64_t n, double p) {
124+
return static_cast<int64_t>(
125+
-n * std::log(p) / (std::log(2.0) * std::log(2.0)));
126+
}
127+
128+
/// Computes m (total bits of Bloom filter) which is expected to achieve.
129+
/// The smaller the expectedNumItems, the smaller the fpp.
130+
///
131+
/// @param expectedNumItems expected number of items to insert.
132+
/// @param maxNumItems maximum number of items.
133+
static int64_t optimalNumOfBits(
134+
int64_t expectedNumItems,
135+
int64_t maxNumItems) {
136+
double ratio = static_cast<double>(expectedNumItems) / maxNumItems;
137+
double fpp = kDefaultFpp * std::min(ratio, 1.0);
138+
return optimalNumOfBits(expectedNumItems, fpp);
139+
}
140+
113141
private:
114142
// We use 4 independent hash functions by taking 24 bits of
115143
// the hash code and breaking these up into 4 groups of 6 bits. Each group
@@ -142,6 +170,8 @@ class BloomFilter {
142170
}
143171

144172
static constexpr int8_t kBloomFilterV1 = 1;
173+
static constexpr double kDefaultFpp = 0.03;
174+
145175
std::vector<uint64_t, Allocator> bits_;
146176
};
147177

velox/common/base/RuntimeMetrics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ BaseRuntimeStatWriter* getThreadLocalRunTimeStatWriter() {
113113
}
114114

115115
void addThreadLocalRuntimeStat(
116-
const std::string& name,
116+
std::string_view name,
117117
const RuntimeCounter& value) {
118118
if (localRuntimeStatWriter) {
119119
localRuntimeStatWriter->addRuntimeStat(name, value);

velox/common/base/RuntimeMetrics.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <fmt/format.h>
2020
#include <folly/CppAttributes.h>
2121
#include <limits>
22+
#include <string_view>
2223

2324
namespace facebook::velox {
2425

@@ -77,7 +78,7 @@ class BaseRuntimeStatWriter {
7778
virtual ~BaseRuntimeStatWriter() = default;
7879

7980
virtual void addRuntimeStat(
80-
const std::string& /* name */,
81+
std::string_view /* name */,
8182
const RuntimeCounter& /* value */) {}
8283
};
8384

@@ -93,7 +94,7 @@ BaseRuntimeStatWriter* getThreadLocalRunTimeStatWriter();
9394

9495
/// Writes runtime counter to the current Operator running on that thread.
9596
void addThreadLocalRuntimeStat(
96-
const std::string& name,
97+
std::string_view name,
9798
const RuntimeCounter& value);
9899

99100
/// Scope guard to conveniently set and revert back the current stat writer.

velox/common/base/tests/BloomFilterTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,28 @@ TEST_F(BloomFilterTest, merge) {
122122

123123
EXPECT_EQ(bloom.serializedSize(), merge.serializedSize());
124124
}
125+
126+
TEST_F(BloomFilterTest, optimalNumOfBitsWithFpp) {
127+
EXPECT_EQ(BloomFilter<>::optimalNumOfBits(1000, 0.03), 7298);
128+
EXPECT_EQ(BloomFilter<>::optimalNumOfBits(1000000, 0.01), 9585058);
129+
EXPECT_EQ(BloomFilter<>::optimalNumOfBits(1, 0.5), 1);
130+
EXPECT_EQ(BloomFilter<>::optimalNumOfBits(1000, 0.001), 14377);
131+
}
132+
133+
TEST_F(BloomFilterTest, optimalNumOfBitsWithMaxItems) {
134+
constexpr int64_t kMaxNumItems = 4'000'000L;
135+
136+
EXPECT_EQ(
137+
BloomFilter<>::optimalNumOfBits(kMaxNumItems, kMaxNumItems), 29'193'763);
138+
139+
EXPECT_EQ(
140+
BloomFilter<>::optimalNumOfBits(1'000'000L, kMaxNumItems), 10'183'830);
141+
142+
EXPECT_EQ(BloomFilter<>::optimalNumOfBits(100L, kMaxNumItems), 2935);
143+
144+
EXPECT_EQ(
145+
BloomFilter<>::optimalNumOfBits(5'000'000L, kMaxNumItems), 36'492'204);
146+
147+
EXPECT_EQ(
148+
BloomFilter<>::optimalNumOfBits(10'000'000L, kMaxNumItems), 72'984'408);
149+
}

0 commit comments

Comments
 (0)