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

[BugFix] MaxBy/MinBy not filter nulls #51354

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

satanson
Copy link
Contributor

@satanson satanson commented Sep 24, 2024

Why I'm doing:

max_by/min_by should not filter nulls, for an example:

  1. prepare data
create table test_table (
   `id` int NOT NULL,
   `name` varchar(10) DEFAULT NULL,
   `grade` int NOT NULL
) ENGINE=OLAP
PRIMARY KEY(`id`)
DISTRIBUTED BY HASH(`id`);

insert into test_table values (1,'john',90);
insert into test_table values (2,'jim',95);
insert into test_table values (3,NULL,100);

  1. query Expected outcome 'null' actual outcome 'jim'
select max_by(name, grade) from test_table;

What I'm doing:

  1. max_by and min_by not filter nulls;
  2. fix ancient bug: crash caused by window query like max_by(T, S) over window_def when S's type is not same to T's

Fixes #issue

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

@satanson satanson requested review from a team as code owners September 24, 2024 13:08
@satanson satanson force-pushed the max_min_by_not_filter_nulls branch from d83b06c to 5947e16 Compare September 25, 2024 11:47
@satanson satanson changed the title [Enhancement] MaxBy/MinBy not filter nulls [UT] MaxBy/MinBy not filter nulls Sep 25, 2024
@satanson satanson force-pushed the max_min_by_not_filter_nulls branch from 5947e16 to b20d5d6 Compare September 26, 2024 02:43
@satanson satanson force-pushed the max_min_by_not_filter_nulls branch from b20d5d6 to 2a28107 Compare September 26, 2024 13:01
Copy link

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 21 / 21 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/catalog/combinator/AggStateDesc.java 1 1 100.00% []
🔵 com/starrocks/analysis/FunctionName.java 1 1 100.00% []
🔵 com/starrocks/catalog/Function.java 19 19 100.00% []

Copy link

[BE Incremental Coverage Report]

fail : 231 / 335 (68.96%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exprs/agg/maxmin_by.h 218 322 67.70% [98, 99, 100, 101, 112, 113, 116, 117, 118, 121, 122, 123, 124, 125, 129, 130, 132, 133, 134, 135, 137, 138, 139, 142, 143, 144, 145, 185, 186, 187, 188, 199, 200, 203, 204, 205, 208, 209, 210, 211, 212, 216, 217, 219, 220, 221, 222, 224, 225, 226, 229, 230, 231, 232, 239, 256, 312, 313, 314, 360, 361, 362, 421, 422, 423, 425, 426, 428, 451, 453, 455, 456, 457, 458, 460, 461, 463, 482, 483, 484, 525, 526, 527, 528, 548, 549, 551, 553, 554, 555, 556, 558, 559, 561, 583, 693, 694, 695, 739, 740, 741, 742, 786, 789]
🔵 be/src/exec/analytor.cpp 7 7 100.00% []
🔵 be/src/exprs/agg/factory/aggregate_factory.cpp 2 2 100.00% []
🔵 be/src/exprs/agg/factory/aggregate_resolver_minmaxany.cpp 4 4 100.00% []

@satanson satanson changed the title [UT] MaxBy/MinBy not filter nulls [Debug] MaxBy/MinBy not filter nulls Sep 27, 2024
@stdpain stdpain changed the title [Debug] MaxBy/MinBy not filter nulls [BugFix] MaxBy/MinBy not filter nulls Sep 27, 2024
"max_by", true, AggregateFactory::MakeMaxByAggregateFunction<arg_type>());
resolver->add_aggregate_mapping_notnull<arg_type, ret_type>(
"max_by", true, AggregateFactory::MakeMaxByAggregateFunction<arg_type, false>());
resolver->add_aggregate_mapping_notnull<arg_type, ret_type>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why using add_aggregate_mapping_notnull? What will happen if y is a nullable column for max_by(x, y) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it seems that nullable columns are handled by MaxBy itself now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, null is acceptable output values, so max_by/min_by agg cannot be wrapped by NullableAggFunction

@kangkaisen kangkaisen merged commit 9398edd into StarRocks:main Sep 27, 2024
86 of 90 checks passed
Copy link

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label Sep 27, 2024
@github-actions github-actions bot removed the 2.5 label Sep 27, 2024
Copy link
Contributor

mergify bot commented Sep 27, 2024

backport branch-3.3

✅ Backports have been created

Copy link
Contributor

mergify bot commented Sep 27, 2024

backport branch-3.2

✅ Backports have been created

Copy link
Contributor

mergify bot commented Sep 27, 2024

backport branch-3.1

✅ Backports have been created

Copy link
Contributor

mergify bot commented Sep 27, 2024

backport branch-3.0

✅ Backports have been created

Copy link
Contributor

mergify bot commented Sep 27, 2024

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)

# Conflicts:
#	be/src/exprs/agg/factory/aggregate_factory.cpp
#	fe/fe-core/src/main/java/com/starrocks/catalog/combinator/AggStateDesc.java
#	test/sql/test_agg_state/R/test_agg_state_table_with_all_functions.sql
mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)

# Conflicts:
#	be/src/exprs/agg/factory/aggregate_factory.cpp
#	fe/fe-core/src/main/java/com/starrocks/catalog/Function.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/combinator/AggStateDesc.java
#	test/sql/test_agg_state/R/test_agg_state_table_with_all_functions.sql
mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)

# Conflicts:
#	be/src/exprs/agg/factory/aggregate_factory.cpp
#	fe/fe-core/src/main/java/com/starrocks/catalog/Function.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/combinator/AggStateDesc.java
#	test/sql/test_agg_state/R/test_agg_state_table_with_all_functions.sql
mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)

# Conflicts:
#	be/src/exprs/agg/factory/aggregate_factory.cpp
#	be/src/exprs/agg/factory/aggregate_factory.hpp
#	be/src/exprs/agg/factory/aggregate_resolver_minmaxany.cpp
#	be/src/exprs/agg/maxmin_by.h
#	be/test/exprs/agg/aggregate_test.cpp
#	fe/fe-core/src/main/java/com/starrocks/catalog/Function.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/FunctionSet.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/combinator/AggStateDesc.java
#	test/sql/test_agg_state/R/test_agg_state_table_with_all_functions.sql
mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)

# Conflicts:
#	be/src/exec/analytor.cpp
#	be/src/exprs/agg/factory/aggregate_factory.cpp
#	be/src/exprs/agg/factory/aggregate_factory.hpp
#	be/src/exprs/agg/factory/aggregate_resolver_minmaxany.cpp
#	be/src/exprs/agg/maxmin_by.h
#	be/test/exprs/agg/aggregate_test.cpp
#	fe/fe-core/src/main/java/com/starrocks/analysis/FunctionName.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/Function.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/FunctionSet.java
#	fe/fe-core/src/main/java/com/starrocks/catalog/combinator/AggStateDesc.java
#	test/sql/test_agg_state/R/test_agg_state_table_with_all_functions.sql
satanson added a commit that referenced this pull request Sep 27, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
satanson added a commit that referenced this pull request Sep 29, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
satanson added a commit that referenced this pull request Sep 29, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
satanson added a commit that referenced this pull request Sep 29, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
wanpengfei-git pushed a commit that referenced this pull request Sep 29, 2024
satanson added a commit that referenced this pull request Sep 29, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
Seaven pushed a commit that referenced this pull request Sep 29, 2024
satanson added a commit that referenced this pull request Sep 29, 2024
Signed-off-by: satanson <[email protected]>
(cherry picked from commit 9398edd)
Signed-off-by: satanson <[email protected]>
wanpengfei-git pushed a commit that referenced this pull request Sep 29, 2024
renzhimin7 pushed a commit to renzhimin7/starrocks that referenced this pull request Nov 7, 2024
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.

5 participants