Skip to content

Check consistency of param N for min_byN/max_byN#21306

Merged
tdcmeehan merged 1 commit intomasterfrom
check-for-consistent-param-n-for-minbyn-maxbyn
Nov 10, 2023
Merged

Check consistency of param N for min_byN/max_byN#21306
tdcmeehan merged 1 commit intomasterfrom
check-for-consistent-param-n-for-minbyn-maxbyn

Conversation

@mmorgan98
Copy link
Contributor

Description

Fixes issue #20920 to check for uniqueness/consistency of N for maxbyN/minbyN aggregate functions.

Motivation and Context

Currently the uniqueness/consistency of param N of minbyN/maxbyN is not checked.

Impact

The test case in issue #20920 now fails as expected:

presto> SELECT max_by(c0, c1, c2)
     ->       FROM (
     ->         VALUES
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '0', BIGINT '10', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '1', BIGINT '9', BIGINT '3'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '2', BIGINT '8', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '3', BIGINT '7', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '4', BIGINT '6', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '5', BIGINT '5', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '6', BIGINT '4', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '7', BIGINT '3', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '8', BIGINT '2', BIGINT '2'),
     ->           (cast(NULL as BIGINT), cast(NULL as BIGINT), cast(NULL as BIGINT)),
     ->           (BIGINT '9', BIGINT '1', BIGINT '2')
     ->       ) AS tmp (c0, c1, c2);

Query 20231103_190942_00004_r6sfw, FAILED, 1 node
Splits: 1 total, 0 done (0.00%)
[Latency: client-side: 97ms, server-side: 68ms] [0 rows, 0B] [0 rows/s, 0B/s]

Query 20231103_190942_00004_r6sfw failed: Count argument is not constant: found multiple values [3, 2]

Test Plan

Added UT testInconsistentN() inside /presto-main/src/test/java/com/facebook/presto/operator/aggregation/minmaxby/TestMinMaxByNAggregation.java

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* minbyN/maxbyN's third argument (N) is now checked to be unique.

@mmorgan98 mmorgan98 requested a review from a team as a code owner November 3, 2023 19:22
@mmorgan98 mmorgan98 requested a review from presto-oss November 3, 2023 19:22
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 3, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: mmorgan98 / name: Matthew Morgan (e304fa9)

@mmorgan98
Copy link
Contributor Author

Signed CLA

Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

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

LGTM % nit on the test

Comment on lines 296 to 301
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Test
public void testInconsistentN()
{
JavaAggregationFunctionImplementation function = getMaxByAggregation(BIGINT, BIGINT, BIGINT);
try {
groupedAggregation(function, new Page(createDoublesBlock(new Double[] {3.0, 2.0, 1.0}), createDoublesBlock(new Double[] {1.0, 2.0, 3.0}), createLongsBlock(new Long[] {2L, 2L, 3L})));
}
catch (PrestoException e) {
assertEquals(e.getMessage(), "Count argument is not constant: found multiple values [3, 2]");
}
}
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Count argument is not constant: found multiple values [3, 2")
public void testInconsistentN()
{
JavaAggregationFunctionImplementation function = getMaxByAggregation(BIGINT, BIGINT, BIGINT);
groupedAggregation(function, new Page(createDoublesBlock(new Double[] {3.0, 2.0, 1.0}), createDoublesBlock(new Double[] {1.0, 2.0, 3.0}), createLongsBlock(new Long[] {2L, 2L, 3L})));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See latest commit

@tdcmeehan tdcmeehan requested a review from kaikalur November 3, 2023 19:30
@tdcmeehan
Copy link
Contributor

CC: @xumingming

@xumingming
Copy link
Contributor

Thanks @mmorgan1230 @tdcmeehan

@mmorgan98 mmorgan98 force-pushed the check-for-consistent-param-n-for-minbyn-maxbyn branch 2 times, most recently from d1a73bd to 29d1ff8 Compare November 6, 2023 14:38
@mmorgan98
Copy link
Contributor Author

FYI - had to reset back 1 commit as I had the incorrect local git config setup. I recommitted the same content as the initial commit that was reviewed and will update the test with a follow up commit.

@tdcmeehan tdcmeehan self-assigned this Nov 6, 2023
@mmorgan98 mmorgan98 requested a review from tdcmeehan November 6, 2023 15:18
@tdcmeehan
Copy link
Contributor

LGTM! Please squash commits and I can approve.

PR item update testInconsistentN for maxbyN/minbyN
@mmorgan98 mmorgan98 force-pushed the check-for-consistent-param-n-for-minbyn-maxbyn branch from 40814f0 to e304fa9 Compare November 6, 2023 15:29
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