Skip to content

Commit 2e129c5

Browse files
zhli1142015meta-codesync[bot]
authored andcommitted
refactor(exec): Move window files under exec/window (#17710)
Summary: Preparatory, mechanical refactor for #17558. The window subsystem lived as a flat set of files under `velox/exec/`. This moves the internal implementation files into a dedicated `velox/exec/window/` directory and `facebook::velox::exec::window` namespace, while keeping the public-facing files in `velox/exec/` and the `facebook::velox::exec` namespace. **Stay in `velox/exec/` (`exec` namespace):** - `Window.h`/`.cpp` — the operator itself, alongside `HashJoin`, `Aggregate`, and `TableScan`. - `WindowFunction.h`/`.cpp` — the public API that window function authors implement against, like `AggregateFunction.h`. **Move under `velox/exec/window/` (`exec::window` namespace):** - `WindowBuild` and its variants, `WindowPartition`, `AggregateWindow`, `KRangeFrameBound`, `PeerGroupComputation`, `WindowPartitionAccessor` — internal implementation details. There are no behavior changes; only file locations, the enclosing namespace of the internal files, and references to them change. The operator and the public API reference the internal types through the `window::` namespace. Pull Request resolved: #17710 Reviewed By: apurva-meta Differential Revision: D107420866 Pulled By: bikramSingh91 fbshipit-source-id: 7a9a306463fd5005d5b48db395d58afde2d32ea0
1 parent 11d690a commit 2e129c5

22 files changed

Lines changed: 115 additions & 93 deletions

velox/exec/Aggregate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <unordered_map>
2020
#include "velox/exec/AggregateCompanionAdapter.h"
2121
#include "velox/exec/AggregateCompanionSignatures.h"
22-
#include "velox/exec/AggregateWindow.h"
22+
#include "velox/exec/window/AggregateWindow.h"
2323

2424
namespace facebook::velox::exec {
2525

@@ -86,7 +86,7 @@ AggregateRegistrationResult registerAggregateFunction(
8686
// If the aggregate is not a companion function, also register it as a window
8787
// function.
8888
if (!metadata.companionFunction) {
89-
registerAggregateWindowFunction(sanitizedName);
89+
window::registerAggregateWindowFunction(sanitizedName);
9090
}
9191

9292
// Register companion function if needed.

velox/exec/CMakeLists.txt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ velox_add_library(
1919
AggregateCompanionSignatures.cpp
2020
AggregateFunctionRegistry.cpp
2121
AggregateInfo.cpp
22-
AggregateWindow.cpp
2322
AggregationMasks.cpp
2423
ArrowStream.cpp
2524
AssignUniqueId.cpp
@@ -76,19 +75,15 @@ velox_add_library(
7675
OutputBufferManager.cpp
7776
ParallelProject.cpp
7877
PartitionFunction.cpp
79-
PartitionStreamingWindowBuild.cpp
8078
PartitionedOutput.cpp
8179
PlanNodeStats.cpp
8280
PrefixSort.cpp
8381
ProbeOperatorState.cpp
84-
SubPartitionedSortWindowBuild.cpp
8582
RowContainer.cpp
8683
RowNumber.cpp
87-
RowsStreamingWindowBuild.cpp
8884
ScaleWriterLocalPartition.cpp
8985
ScaledScanController.cpp
9086
SortBuffer.cpp
91-
SortWindowBuild.cpp
9287
SortedAggregations.cpp
9388
SpatialJoinBuild.cpp
9489
SpatialJoinProbe.cpp
@@ -111,7 +106,6 @@ velox_add_library(
111106
Values.cpp
112107
VectorHasher.cpp
113108
Window.cpp
114-
WindowBuild.cpp
115109
WindowFunction.cpp
116110
WindowPartition.cpp
117111
HEADERS
@@ -122,7 +116,6 @@ velox_add_library(
122116
AggregateCompanionSignatures.h
123117
AggregateFunctionRegistry.h
124118
AggregateInfo.h
125-
AggregateWindow.h
126119
AggregationMasks.h
127120
ArrowStream.h
128121
AssignUniqueId.h
@@ -156,7 +149,6 @@ velox_add_library(
156149
IndexLookupJoin.h
157150
IndexLookupJoinBridge.h
158151
JoinBridge.h
159-
KRangeFrameBound.h
160152
Limit.h
161153
LocalPartition.h
162154
LocalPlanner.h
@@ -182,24 +174,20 @@ velox_add_library(
182174
OutputBuffer.h
183175
OutputBufferManager.h
184176
ParallelProject.h
185-
PeerGroupComputation.h
186177
PartitionFunction.h
187-
PartitionStreamingWindowBuild.h
188178
PartitionedOutput.h
189179
PlanNodeStats.h
190180
PrefixSort.h
191181
ProbeOperatorState.h
192182
RoundRobinPartitionFunction.h
193183
RowContainer.h
194184
RowNumber.h
195-
RowsStreamingWindowBuild.h
196185
ScaleWriterLocalPartition.h
197186
ScaledScanController.h
198187
SerializedPage.h
199188
SetAccumulator.h
200189
SimpleAggregateAdapter.h
201190
SortBuffer.h
202-
SortWindowBuild.h
203191
SortedAggregations.h
204192
SpatialIndex.h
205193
SpatialJoinBuild.h
@@ -211,7 +199,6 @@ velox_add_library(
211199
StreamingAggregation.h
212200
StreamingEnforceDistinct.h
213201
Strings.h
214-
SubPartitionedSortWindowBuild.h
215202
TableScan.h
216203
TableWriteMerge.h
217204
TableWriter.h
@@ -229,10 +216,8 @@ velox_add_library(
229216
VectorHasher-inl.h
230217
VectorHasher.h
231218
Window.h
232-
WindowBuild.h
233219
WindowFunction.h
234220
WindowPartition.h
235-
WindowPartitionAccessor.h
236221
)
237222

238223
velox_add_library(velox_exec_spill_stats SpillStats.cpp HEADERS SpillStats.h)
@@ -247,6 +232,7 @@ velox_link_libraries(
247232
velox_connector
248233
velox_connector_registry
249234
velox_exec_spill_stats
235+
velox_exec_window
250236
velox_expression
251237
velox_file
252238
velox_presto_serializer
@@ -279,6 +265,7 @@ endif()
279265
add_subdirectory(prefixsort)
280266
add_subdirectory(rpc)
281267
add_subdirectory(trace)
268+
add_subdirectory(window)
282269

283270
velox_add_library(velox_aggregate_util INTERFACE HEADERS AggregateUtil.h)
284271

velox/exec/Window.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#include "velox/exec/Window.h"
1717
#include "velox/exec/OperatorType.h"
1818
#include "velox/exec/OperatorUtils.h"
19-
#include "velox/exec/PartitionStreamingWindowBuild.h"
20-
#include "velox/exec/RowsStreamingWindowBuild.h"
21-
#include "velox/exec/SortWindowBuild.h"
22-
#include "velox/exec/SubPartitionedSortWindowBuild.h"
2319
#include "velox/exec/Task.h"
20+
#include "velox/exec/window/PartitionStreamingWindowBuild.h"
21+
#include "velox/exec/window/RowsStreamingWindowBuild.h"
22+
#include "velox/exec/window/SortWindowBuild.h"
23+
#include "velox/exec/window/SubPartitionedSortWindowBuild.h"
2424

2525
namespace facebook::velox::exec {
2626

@@ -62,17 +62,17 @@ Window::Window(
6262
}
6363
if (windowNode->inputsSorted()) {
6464
if (supportRowsStreaming()) {
65-
windowBuild_ = std::make_unique<RowsStreamingWindowBuild>(
65+
windowBuild_ = std::make_unique<window::RowsStreamingWindowBuild>(
6666
windowNode_, pool(), spillConfig, &nonReclaimableSection_);
6767
} else {
68-
windowBuild_ = std::make_unique<PartitionStreamingWindowBuild>(
68+
windowBuild_ = std::make_unique<window::PartitionStreamingWindowBuild>(
6969
windowNode, pool(), spillConfig, &nonReclaimableSection_);
7070
}
7171
} else {
7272
if (auto numSubPartitions =
7373
operatorCtx_->driverCtx()->queryConfig().windowNumSubPartitions();
7474
numSubPartitions > 1) {
75-
windowBuild_ = std::make_unique<SubPartitionedSortWindowBuild>(
75+
windowBuild_ = std::make_unique<window::SubPartitionedSortWindowBuild>(
7676
windowNode,
7777
numSubPartitions,
7878
pool(),
@@ -82,7 +82,7 @@ Window::Window(
8282
&stats_,
8383
spillStats_.get());
8484
} else {
85-
windowBuild_ = std::make_unique<SortWindowBuild>(
85+
windowBuild_ = std::make_unique<window::SortWindowBuild>(
8686
windowNode,
8787
pool(),
8888
makePrefixSortConfig(driverCtx->queryConfig()),

velox/exec/Window.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#include "velox/exec/Operator.h"
1919
#include "velox/exec/RowContainer.h"
20-
#include "velox/exec/WindowBuild.h"
2120
#include "velox/exec/WindowFunction.h"
2221
#include "velox/exec/WindowPartition.h"
22+
#include "velox/exec/window/WindowBuild.h"
2323

2424
namespace facebook::velox::exec {
2525

@@ -171,7 +171,7 @@ class Window : public Operator {
171171

172172
// WindowBuild is used to store input rows and return WindowPartitions
173173
// for the processing.
174-
std::unique_ptr<WindowBuild> windowBuild_;
174+
std::unique_ptr<window::WindowBuild> windowBuild_;
175175

176176
// The cached window plan node used for window function initialization. It is
177177
// reset after the initialization.

velox/exec/WindowPartition.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
#include "velox/exec/WindowPartition.h"
17-
#include "velox/exec/KRangeFrameBound.h"
18-
#include "velox/exec/PeerGroupComputation.h"
17+
#include "velox/exec/window/KRangeFrameBound.h"
18+
#include "velox/exec/window/PeerGroupComputation.h"
1919

2020
#include <algorithm>
2121

@@ -287,7 +287,7 @@ std::pair<vector_size_t, vector_size_t> WindowPartition::computePeerBuffers(
287287
vector_size_t* rawPeerStarts,
288288
vector_size_t* rawPeerEnds) {
289289
RowContainerAccessor rows{*this};
290-
auto result = PeerGroupComputation::compute(
290+
auto result = window::PeerGroupComputation::compute(
291291
rows, start, end, prevPeerStart, prevPeerEnd, rawPeerStarts, rawPeerEnds);
292292
if (result.previousRowConsumed) {
293293
removePreviousRow();
@@ -308,7 +308,7 @@ void WindowPartition::computeKRangeFrameBounds(
308308
const auto frameType = data_->columnTypes()[inputMapping_[frameColumn]];
309309

310310
RowContainerAccessor rows{*this};
311-
KRangeFrameBound::compute(
311+
window::KRangeFrameBound::compute(
312312
rows,
313313
isStartBound,
314314
isPreceding,

velox/exec/tests/WindowTest.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include "velox/common/testutil/TempDirectoryPath.h"
2222
#include "velox/exec/OrderBy.h"
2323
#include "velox/exec/PlanNodeStats.h"
24-
#include "velox/exec/RowsStreamingWindowBuild.h"
25-
#include "velox/exec/SortWindowBuild.h"
2624
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
2725
#include "velox/exec/tests/utils/OperatorTestBase.h"
2826
#include "velox/exec/tests/utils/PlanBuilder.h"
27+
#include "velox/exec/window/RowsStreamingWindowBuild.h"
28+
#include "velox/exec/window/SortWindowBuild.h"
2929
#include "velox/functions/prestosql/window/WindowFunctionsRegistration.h"
3030

3131
using namespace facebook::velox::exec::test;
@@ -38,7 +38,7 @@ class WindowTest : public OperatorTestBase {
3838
public:
3939
void SetUp() override {
4040
OperatorTestBase::SetUp();
41-
window::prestosql::registerAllWindowFunctions();
41+
velox::window::prestosql::registerAllWindowFunctions();
4242
filesystems::registerLocalFileSystem();
4343
}
4444

@@ -348,9 +348,9 @@ DEBUG_ONLY_TEST_F(WindowTest, aggWindowResultMismatch) {
348348

349349
std::atomic_bool isStreamCreated{false};
350350
SCOPED_TESTVALUE_SET(
351-
"facebook::velox::exec::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
352-
std::function<void(RowsStreamingWindowBuild*)>(
353-
[&](RowsStreamingWindowBuild* windowBuild) {
351+
"facebook::velox::exec::window::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
352+
std::function<void(window::RowsStreamingWindowBuild*)>(
353+
[&](window::RowsStreamingWindowBuild* windowBuild) {
354354
isStreamCreated.store(true);
355355
}));
356356

@@ -381,9 +381,9 @@ DEBUG_ONLY_TEST_F(WindowTest, rankRowStreamingWindowBuild) {
381381

382382
std::atomic_bool isStreamCreated{false};
383383
SCOPED_TESTVALUE_SET(
384-
"facebook::velox::exec::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
385-
std::function<void(RowsStreamingWindowBuild*)>(
386-
[&](RowsStreamingWindowBuild* windowBuild) {
384+
"facebook::velox::exec::window::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
385+
std::function<void(window::RowsStreamingWindowBuild*)>(
386+
[&](window::RowsStreamingWindowBuild* windowBuild) {
387387
isStreamCreated.store(true);
388388
}));
389389

@@ -424,9 +424,9 @@ DEBUG_ONLY_TEST_F(WindowTest, valuesRowsStreamingWindowBuild) {
424424

425425
std::atomic_bool isStreamCreated{false};
426426
SCOPED_TESTVALUE_SET(
427-
"facebook::velox::exec::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
428-
std::function<void(RowsStreamingWindowBuild*)>(
429-
[&](RowsStreamingWindowBuild* windowBuild) {
427+
"facebook::velox::exec::window::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
428+
std::function<void(window::RowsStreamingWindowBuild*)>(
429+
[&](window::RowsStreamingWindowBuild* windowBuild) {
430430
isStreamCreated.store(true);
431431
}));
432432

@@ -577,9 +577,9 @@ DEBUG_ONLY_TEST_F(WindowTest, aggregationWithNonDefaultFrame) {
577577

578578
std::atomic_bool isStreamCreated{false};
579579
SCOPED_TESTVALUE_SET(
580-
"facebook::velox::exec::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
581-
std::function<void(RowsStreamingWindowBuild*)>(
582-
[&](RowsStreamingWindowBuild* windowBuild) {
580+
"facebook::velox::exec::window::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
581+
std::function<void(window::RowsStreamingWindowBuild*)>(
582+
[&](window::RowsStreamingWindowBuild* windowBuild) {
583583
isStreamCreated.store(true);
584584
}));
585585

@@ -610,9 +610,9 @@ DEBUG_ONLY_TEST_F(WindowTest, nonRowsStreamingWindow) {
610610

611611
std::atomic_bool isStreamCreated{false};
612612
SCOPED_TESTVALUE_SET(
613-
"facebook::velox::exec::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
614-
std::function<void(RowsStreamingWindowBuild*)>(
615-
[&](RowsStreamingWindowBuild* windowBuild) {
613+
"facebook::velox::exec::window::RowsStreamingWindowBuild::RowsStreamingWindowBuild",
614+
std::function<void(window::RowsStreamingWindowBuild*)>(
615+
[&](window::RowsStreamingWindowBuild* windowBuild) {
616616
isStreamCreated.store(true);
617617
}));
618618

@@ -889,7 +889,7 @@ DEBUG_ONLY_TEST_F(WindowTest, reserveMemorySort) {
889889
velox::common::PrefixSortConfig{
890890
std::numeric_limits<int32_t>::max(), 130, 12};
891891
folly::Synchronized<OperatorStats> opStats;
892-
auto sortWindowBuild = std::make_unique<SortWindowBuild>(
892+
auto sortWindowBuild = std::make_unique<window::SortWindowBuild>(
893893
plan,
894894
pool_.get(),
895895
std::move(prefixSortConfig),
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "velox/exec/AggregateWindow.h"
17+
#include "velox/exec/window/AggregateWindow.h"
1818
#include "velox/common/base/Exceptions.h"
1919
#include "velox/exec/Aggregate.h"
2020
#include "velox/exec/WindowFunction.h"
2121
#include "velox/expression/FunctionSignature.h"
2222
#include "velox/vector/FlatVector.h"
2323

24-
namespace facebook::velox::exec {
24+
namespace facebook::velox::exec::window {
2525

2626
namespace {
2727

@@ -435,4 +435,4 @@ void registerAggregateWindowFunction(const std::string& name) {
435435
});
436436
}
437437
}
438-
} // namespace facebook::velox::exec
438+
} // namespace facebook::velox::exec::window
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#pragma once
1717
#include <string>
1818

19-
namespace facebook::velox::exec {
19+
namespace facebook::velox::exec::window {
2020

2121
void registerAggregateWindowFunction(const std::string& name);
2222

23-
} // namespace facebook::velox::exec
23+
} // namespace facebook::velox::exec::window

velox/exec/window/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
velox_add_library(
16+
velox_exec_window
17+
AggregateWindow.cpp
18+
PartitionStreamingWindowBuild.cpp
19+
RowsStreamingWindowBuild.cpp
20+
SortWindowBuild.cpp
21+
SubPartitionedSortWindowBuild.cpp
22+
WindowBuild.cpp
23+
HEADERS
24+
AggregateWindow.h
25+
KRangeFrameBound.h
26+
PartitionStreamingWindowBuild.h
27+
PeerGroupComputation.h
28+
RowsStreamingWindowBuild.h
29+
SortWindowBuild.h
30+
SubPartitionedSortWindowBuild.h
31+
WindowBuild.h
32+
WindowPartitionAccessor.h
33+
)
34+
35+
velox_link_libraries(velox_exec_window velox_exec velox_vector)

0 commit comments

Comments
 (0)