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

Adds basic aggregations to the partiql-planner #1247

Merged
merged 8 commits into from
Oct 20, 2023

Conversation

RCHowell
Copy link
Member

Description

This PR adds basic aggregations to the resolved planner. We define aggregation functions in the header and resolve to one of the available / defined operators. Like a SELECT list, each GROUP BY key gets its own unique binder.

At the moment, this work is not thoroughly tested, but behaves as desired for the 12 sanity tests. This does not include the SQL++ GROUP AS.

Other Information

  • Updated Unreleased Section in CHANGELOG: [YES/NO]
    No

  • Any backward-incompatible changes? [YES/NO]
    No partiql-planner is a new package

  • Any new external dependencies? [YES/NO]
    No

  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES/NO]
    Yes

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

github-actions bot commented Oct 16, 2023

Conformance comparison report

Base (5ca3723) f1944e8 +/-
% Passing 92.33% 92.33% 0.00%
✅ Passing 5372 5372 0
❌ Failing 446 446 0
🔶 Ignored 0 0 0
Total Tests 5818 5818 0

Number passing in both: 5372

Number failing in both: 446

Number passing in Base (5ca3723) but now fail: 0

Number failing in Base (5ca3723) but now pass: 0

@RCHowell RCHowell requested a review from johnedquinn October 18, 2023 18:12
Copy link
Member

@johnedquinn johnedquinn left a comment

Choose a reason for hiding this comment

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

Overall looks good. I'm skimming through the inference tests, and could you add tests specifically dedicated to aggregations with only group by keys and no agg functions? Ideally, with some positive tests and negative tests where the input arguments are nullable, missing, potentially missing, potentially the wrong type, and definitely of the wrong type?

var missingArg = false
val args = arguments.map {
val arg = visitRex(it, null)
if (arg.type == MissingType) missingArg = true
Copy link
Member

Choose a reason for hiding this comment

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

What happens if it's a union including missing? Or, if we're trying to compute COUNT and the argument is always a string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe the COUNT column type matters. The SQL spec doesn't show anything about the input argument type to COUNT (as far as I can tell), only the output being exact numeric.

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched arg.type == MissingType to arg.type.isMissable

@RCHowell RCHowell requested a review from johnedquinn October 19, 2023 20:53
Copy link
Member

@johnedquinn johnedquinn left a comment

Choose a reason for hiding this comment

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

Overall, this looks good to ship. Have some clean-up comments, but once rebased and addressed, I can approve.


// Some operators can return MISSING during runtime
if (match.isMissable) {
type = StaticType.unionOf(type, StaticType.MISSING)
Copy link
Member

Choose a reason for hiding this comment

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

While it's not an explicit requirement within PlanTyper, several functions in the PlanTyper flatten their union types before returning. Helps avoid accidental breaks in the future.

Here, you could potentially have a type = union(union(type, NULL), MISSING) -- which, I don't think all functions account for. When you call allTypes, you typically wouldn't expect any AnyOfType's to be part of the return.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's very odd StaticType behavior. Union is an associative operation you'd expect

(A U B) U (B U C)    <-->  A U B U C

The need to flatten is a workaround for StaticType union not being associative

if (!hadMissingArg && arg.type.isMissable()) {
hadMissingArg = true
}
arg.type.isNullOrMissing()
Copy link
Member

Choose a reason for hiding this comment

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

Left behind

@RCHowell RCHowell force-pushed the planner-aggregations branch from e51c035 to 11ff840 Compare October 20, 2023 16:45
@RCHowell RCHowell requested a review from johnedquinn October 20, 2023 17:27
@RCHowell RCHowell merged commit 72a76cc into partiql-planner Oct 20, 2023
8 of 10 checks passed
@RCHowell RCHowell deleted the planner-aggregations branch October 20, 2023 17:54
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.

2 participants