Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions velox/exec/StreamingAggregation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ void StreamingAggregation::assignGroups() {
auto numInput = input_->size();

inputGroups_.resize(numInput);

// Look for the end of the last group.
vector_size_t index = 0;
if (prevInput_) {
if (prevInput_ && numGroups_ > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为何要加这个条件?

auto prevIndex = prevInput_->size() - 1;
auto* prevGroup = groups_[numGroups_ - 1];
for (; index < numInput; ++index) {
Expand Down Expand Up @@ -334,10 +333,9 @@ RowVectorPtr StreamingAggregation::getOutput() {
evaluateAggregates();

RowVectorPtr output;

if (numGroups_ > minOutputBatchSize_) {
if (numGroups_ >= minOutputBatchSize_) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有必要改?

Copy link
Copy Markdown
Author

@KevinyhZou KevinyhZou Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对,velox 里面minOutputBatchSize 最小只能取1, numGroups > minOutputBatchSize 意味着当只有一条数据的时候,是不输出的,这不符合流计算的场景。

output = createOutput(
std::min(numGroups_ - 1, static_cast<size_t>(maxOutputBatchSize_)));
std::min(numGroups_, static_cast<size_t>(maxOutputBatchSize_)));
}

prevInput_ = input_;
Expand Down
12 changes: 5 additions & 7 deletions velox/experimental/stateful/GroupWindowAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ void GroupWindowAggregator::advance() {
}

// 1. Partition input by key
std::map<uint32_t, RowVectorPtr> keyToData = keySelector_->partition(input_);
std::map<int64_t, RowVectorPtr> keyToData = keySelector_->partition(input_);
for (const auto& [key, keyedData] : keyToData) {
// 2. Set the current key in the context
windowContext_->setCurrentKey(key);
// 3. Partition the keyed data by rowtime or processing time
std::map<uint32_t, RowVectorPtr> timestampToData =
sliceAssigner_->assignSliceEnd(keyedData);
std::map<int64_t, RowVectorPtr> timestampToData = sliceAssigner_->assignSliceEnd(keyedData);
for (const auto& [timestamp, data] : timestampToData) {
// 4. Assign data to window
std::vector<TimeWindow> windows =
Expand Down Expand Up @@ -124,7 +123,7 @@ void GroupWindowAggregator::advance() {
}

void GroupWindowAggregator::onEventTime(
std::shared_ptr<TimerHeapInternalTimer<uint32_t, TimeWindow>> timer) {
std::shared_ptr<TimerHeapInternalTimer<int64_t, TimeWindow>> timer) {
windowContext_->setCurrentKey(timer->key());
if (triggerContext_->onEventTime(timer->ns(), timer->timestamp())) {
// Fire the window and emit result.
Expand Down Expand Up @@ -187,7 +186,7 @@ void GroupWindowAggregator::emitWindowResult(uint32_t key, TimeWindow window) {

GroupWindowAggregator::WindowTriggerContext::WindowTriggerContext(
std::shared_ptr<WindowTrigger> trigger,
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>>
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>>
internalTimerService,
int shiftTimeZone)
: trigger_(std::move(trigger)),
Expand Down Expand Up @@ -236,7 +235,6 @@ int64_t GroupWindowAggregator::WindowTriggerContext::getCurrentWatermark() {
void GroupWindowAggregator::WindowTriggerContext::registerProcessingTimeTimer(
uint32_t key,
TimeWindow window,

int64_t time) {
internalTimerService_->registerProcessingTimeTimer(key, window, time);
}
Expand Down Expand Up @@ -287,7 +285,7 @@ void GroupWindowAggregator::WindowTriggerContext::mergePartitionedState(
WindowContext::WindowContext(
GroupWindowAggsHandler* windowAggregator,
std::shared_ptr<ValueState<uint32_t, TimeWindow, RowVectorPtr>> windowState,
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>> timerService,
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>> timerService,
std::shared_ptr<TriggerContext> triggerContext,
std::shared_ptr<StreamOperatorStateHandler> stateHandler,
int shiftTimeZone,
Expand Down
15 changes: 7 additions & 8 deletions velox/experimental/stateful/GroupWindowAggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "velox/experimental/stateful/TimerHeapInternalTimer.h"
#include "velox/experimental/stateful/Triggerable.h"
#include "velox/experimental/stateful/window/SliceAssigner.h"
#include "velox/experimental/stateful/window/WindowBuffer.h"
#include "velox/experimental/stateful/window/WindowProcessFunction.h"
#include "velox/experimental/stateful/window/WindowTrigger.h"

Expand All @@ -33,7 +32,7 @@ class WindowContext;
/// This class is related to AggregateWindowOperator in Flink.
/// It's for group window aggregator. Rename it to GroupWindowAggregator.
class GroupWindowAggregator : public StatefulOperator,
public Triggerable<uint32_t, TimeWindow> {
public Triggerable<int64_t, TimeWindow> {
public:
GroupWindowAggregator(
std::unique_ptr<GroupWindowAggsHandler> windowAggerator,
Expand Down Expand Up @@ -61,7 +60,7 @@ class GroupWindowAggregator : public StatefulOperator,
return "GroupWindowAggregator";
}

void onEventTime(std::shared_ptr<TimerHeapInternalTimer<uint32_t, TimeWindow>>
void onEventTime(std::shared_ptr<TimerHeapInternalTimer<int64_t, TimeWindow>>
timer) override;

private:
Expand All @@ -71,7 +70,7 @@ class GroupWindowAggregator : public StatefulOperator,
public:
WindowTriggerContext(
std::shared_ptr<WindowTrigger> trigger,
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>>
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>>
internalTimerService,
int shiftTimeZone);

Expand Down Expand Up @@ -122,7 +121,7 @@ class GroupWindowAggregator : public StatefulOperator,

private:
std::shared_ptr<WindowTrigger> trigger_;
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>>
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>>
internalTimerService_;
int shiftTimeZone_;
TimeWindow window;
Expand All @@ -145,7 +144,7 @@ class GroupWindowAggregator : public StatefulOperator,

RowVectorPtr input_;
std::shared_ptr<ValueState<uint32_t, TimeWindow, RowVectorPtr>> windowState_;
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>>
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>>
windowTimerService_;
std::shared_ptr<TriggerContext> triggerContext_;
std::shared_ptr<WindowContext> windowContext_;
Expand All @@ -158,7 +157,7 @@ class WindowContext : public FunctionContext<TimeWindow> {
GroupWindowAggsHandler* windowAggregator,
std::shared_ptr<ValueState<uint32_t, TimeWindow, RowVectorPtr>>
windowState,
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>> timerService,
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>> timerService,
std::shared_ptr<TriggerContext> triggerContext,
std::shared_ptr<StreamOperatorStateHandler> stateHandler,
int shiftTimeZone,
Expand Down Expand Up @@ -201,7 +200,7 @@ class WindowContext : public FunctionContext<TimeWindow> {
std::shared_ptr<ValueState<uint32_t, TimeWindow, RowVectorPtr>> windowState_;
std::shared_ptr<ValueState<uint32_t, TimeWindow, RowVectorPtr>>
previousWindowState_;
std::shared_ptr<InternalTimerService<uint32_t, TimeWindow>> timerService_;
std::shared_ptr<InternalTimerService<int64_t, TimeWindow>> timerService_;
std::shared_ptr<TriggerContext> triggerContext_;
std::shared_ptr<StreamOperatorStateHandler> stateHandler_;
int shiftTimeZone_;
Expand Down
Loading