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

[Enhancement] Support aggregate function map_agg. #51967

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

Jcnessss
Copy link
Contributor

@Jcnessss Jcnessss commented Oct 16, 2024

Why I'm doing:

Map_agg is an aggregate function to generate map value, which is frequently used in Trino. To support migrate from Trino to Starrocks, develop the same function in Starrocks.

Related issue #40894

What I'm doing:

I tried 3 ways to develop this function:

  1. Using template: key type as KT, value type as VT, in which case neither the key or value could be complex type.
  2. Not using template: Both key and value could be complex type, however, we need to call map_column#remove_duplicated_keys, and there is a triple loop in it, which will highly decrease the performance of map_agg.
  3. Using template: key type as KT, in which case the value could be complex type.

I think the 3rd one will be the best one, and the behavior is just like Trino.

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.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@Jcnessss Jcnessss requested review from a team as code owners October 16, 2024 07:07
be/src/exprs/agg/map_agg.h Outdated Show resolved Hide resolved
be/src/exprs/agg/map_agg.h Outdated Show resolved Hide resolved
using KeyType = typename SliceHashSet::key_type;

MyHashMap hash_map;
void update(MemPool* mem_pool,
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems other system implement has a max limit for map_agg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. It seems that the map_agg of Trino does not have a limit, all my implement is simulating the one in Trino.

@Jcnessss
Copy link
Contributor Author

@stdpain Thanks for the review again! I have changed the code according to your review. Could you please help me review again?

@Jcnessss Jcnessss requested a review from stdpain October 16, 2024 11:18
stdpain
stdpain previously approved these changes Oct 17, 2024
@Jcnessss
Copy link
Contributor Author

@stdpain Thanks for all the reviews!

@Jcnessss
Copy link
Contributor Author

@stdpain Hi, I'm sorry that I forgot to commit a part of FE codes. Could you please review this again?

@stdpain
Copy link
Contributor

stdpain commented Oct 22, 2024

https://github.com/Mergifyio rebase main

Copy link
Contributor

mergify bot commented Oct 22, 2024

rebase main

❌ Unable to rebase: user stdpain is unknown.

Please make sure stdpain has logged in Mergify dashboard.

@stdpain
Copy link
Contributor

stdpain commented Oct 22, 2024

https://github.com/Mergifyio rebase main

Copy link
Contributor

mergify bot commented Oct 22, 2024

rebase main

✅ Branch has been successfully rebased

@Jcnessss Jcnessss force-pushed the map_agg branch 3 times, most recently from d6cd77d to dde5d83 Compare October 28, 2024 02:16
@Jcnessss
Copy link
Contributor Author

Jcnessss commented Oct 28, 2024

@stdpain Hello, the CI passed(The failure in admit test seems has nothing with this PR.) and I have changed the implement way of the value in map, using a column to store values instead in order to keep the reference of slices.
Could you please look at this again?

@Jcnessss Jcnessss force-pushed the map_agg branch 2 times, most recently from c1a7ef4 to 19cab15 Compare October 30, 2024 02:12
key_column->append(*src[0], i, 1);
value_column->append(*src[1], i, 1);
offsets.push_back(offsets.back() + 1);
}
Copy link
Contributor

@stdpain stdpain Oct 30, 2024

Choose a reason for hiding this comment

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

Suggested change
}
}
if (dst->is_nullable()) {
down_cast<NullableColumn*>(dst)->null_column_data().resize(dst->size() + chunk_size);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! Done.

Copy link

sonarcloud bot commented Oct 31, 2024

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 19 / 19 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/catalog/FunctionSet.java 17 17 100.00% []
🔵 com/starrocks/sql/analyzer/PolymorphicFunctionAnalyzer.java 2 2 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 70 / 84 (83.33%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exprs/agg/map_agg.h 61 75 81.33% [55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 109, 110, 111, 157]
🔵 be/src/exprs/agg/factory/aggregate_resolver_avg.cpp 9 9 100.00% []

@Jcnessss Jcnessss requested a review from stdpain October 31, 2024 05:53
@stdpain stdpain enabled auto-merge (squash) November 7, 2024 13:27
@stdpain stdpain merged commit b8447fb into StarRocks:main Nov 8, 2024
53 of 54 checks passed
@Jcnessss
Copy link
Contributor Author

Jcnessss commented Nov 8, 2024

Thanks for all the reviews!

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.

5 participants