Skip to content

Conversation

@daju233
Copy link

@daju233 daju233 commented Jan 23, 2026

What problem does this PR solve?

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@daju233 daju233 requested a review from zclllyybb as a code owner January 23, 2026 11:21
@hello-stephen
Copy link
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@daju233 daju233 force-pushed the dev-daju233 branch 2 times, most recently from 866f02d to 8317b21 Compare January 23, 2026 11:46
@zclllyybb zclllyybb self-assigned this Jan 23, 2026
return comb;
}

bool _next_combination(std::vector<size_t>& comb, Int64 k) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the meaning of I, j, k? dont use those meaningless identifier


Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
uint32_t result, size_t input_rows_count) const override {
auto left = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
Copy link
Contributor

Choose a reason for hiding this comment

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

dont directly use convert_to_full_column_if_const, but vector_const...

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
uint32_t result, size_t input_rows_count) const override {
auto left = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
auto* src_arr = assert_cast<ColumnArray*>(remove_nullable(left)->assume_mutable().get());
Copy link
Contributor

Choose a reason for hiding this comment

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

why need assume_mutable here?

"array_combinations first argument must be Array");
DataType itemType = ((ArrayType) arg0Type).getItemType();
return FunctionSignature.ret(ArrayType.of(ArrayType.of(itemType)))
.args(getArgument(0).getDataType(), getArgument(1).getDataType());
Copy link
Contributor

Choose a reason for hiding this comment

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

what if arg1 is not number?

sql """ INSERT INTO t_array_combinations VALUES(1, ['foo','bar','baz'], [1,2,3], [1,2,2], [[1,1],[4,5],[1,4]]) """

qt_test """
select k1, array_combinations(s1, 2), array_combinations(a1, 2), array_combinations(a2, 2), array_combinations(aa1, 2) from t_array_combinations order by k1;
Copy link
Contributor

Choose a reason for hiding this comment

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

there's too few testcases. should add more to cover situations


ColumnPtr _execute_combination(const ColumnArray* nested, size_t input_rows_count,
const ColumnArray::ColumnOffsets& offsets, Int64 k) const {
const auto& data_col = nested->get_data();
Copy link
Contributor

Choose a reason for hiding this comment

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

re-consider all your var names


std::vector comb = _first_combination(k, row_len);

for (int i = 0; i < static_cast<size_t>(k); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why put a single same for-loop outside the while-loop? maybe you need a do-while?

size_t curr_off = in_offs[row];
size_t row_len = curr_off - prev_off;

if (k <= 0 || static_cast<size_t>(k) > row_len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add reg case and make sure this behaviour is same with target system

for (int i = 0; i < static_cast<size_t>(k); ++i) {
size_t idx = prev_off + comb[i];
data_col.get(idx, element);
inner->get_data().insert(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

directly use insert_from could get rid of Field?


ColumnPtr _execute_combination(const ColumnArray* nested, size_t input_rows_count,
const ColumnArray::ColumnOffsets& offsets, Int64 k) const {
const auto& data_col = nested->get_data();
Copy link
Contributor

Choose a reason for hiding this comment

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

you can reserve for result column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants