Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]support max_by/min_by in window op #54961

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

before-Sunrise
Copy link
Contributor

@before-Sunrise before-Sunrise commented Jan 10, 2025

Why I'm doing:

What I'm doing:

Fixes #55077

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
  • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

Signed-off-by: before-Sunrise <[email protected]>
}
}
}

std::string get_name() const override { return "maxmin_by"; }
};

Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Potential null pointer dereference.

You can modify the code like this:

void get_values(FunctionContext* ctx, ConstAggDataPtr __restrict state, Column* dst, size_t start,
                size_t end) const override {
    if (!dst) {
        throw std::invalid_argument("Destination column is nullptr");
    }
    
    if constexpr (State::not_filter_nulls_flag) {
        if (this->data(state).null_result) {
            DCHECK(dst->is_nullable());
            for (size_t i = start; i < end; ++i) {
                dst->append_default();
            }
        } else {
            if (dst->is_nullable()) {
                for (size_t i = start; i < end; ++i) {
                    down_cast<NullableColumn*>(dst)->null_column()->append(DATUM_NOT_NULL);
                }
            }
            for (size_t i = start; i < end; ++i) {
                ColumnHelper::get_data_column(dst)->deserialize_and_append(this->data(state).buffer_result.data());
            }
        }
    } else {
        if (this->data(state).buffer_result.empty()) {
            for (size_t i = start; i < end; ++i) {
                dst->append_default();
            }
        } else {
            if (dst->is_nullable()) {
                for (size_t i = start; i < end; ++i) {
                    down_cast<NullableColumn*>(dst)->null_column()->append(DATUM_NOT_NULL);
                }
            }
            for (size_t i = start; i < end; ++i) {
                ColumnHelper::get_data_column(dst)->deserialize_and_append(this->data(state).buffer_result.data());
            }
        }
    }
}

@alvin-celerdata
Copy link
Contributor

It seems a new feature, you should change this title from bug fix into feature

@before-Sunrise before-Sunrise changed the title [BugFix]support max_by/min_by in window op [Feature]support max_by/min_by in window op Jan 11, 2025
@alvin-celerdata
Copy link
Contributor

@before-Sunrise
Some SQL tests should be added because this new feature is supported.

Signed-off-by: before-Sunrise <[email protected]>
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

fail : 20 / 36 (55.56%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exprs/agg/maxmin_by.h 20 36 55.56% [612, 613, 614, 617, 618, 619, 622, 623, 851, 852, 853, 856, 857, 858, 861, 862]

@kangkaisen kangkaisen merged commit da2ef02 into StarRocks:main Jan 24, 2025
89 of 90 checks passed
Copy link

@Mergifyio backport branch-3.4

Copy link

@Mergifyio backport branch-3.3

Copy link
Contributor

mergify bot commented Jan 24, 2025

backport branch-3.4

✅ Backports have been created

Copy link
Contributor

mergify bot commented Jan 24, 2025

backport branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 24, 2025
Signed-off-by: before-Sunrise <[email protected]>
(cherry picked from commit da2ef02)
mergify bot pushed a commit that referenced this pull request Jan 24, 2025
Signed-off-by: before-Sunrise <[email protected]>
(cherry picked from commit da2ef02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] max_by/min_by should support window operator
4 participants