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

Add support for TDS v2 (relation) groupBy in QueryBuilder #3892

Merged
merged 36 commits into from
Feb 18, 2025

Conversation

travisstebbins
Copy link
Contributor

@travisstebbins travisstebbins commented Feb 12, 2025

Summary

Add support for using the new TDS v2 (relation) protocol with groupBy expressions. This includes

  • Supporting converting the QueryBuilder state to the new protocol when the user has groupBy functions (i.e., count, sum, etc.)
  • Supporting converting the new protocol with groupBy functions to QueryBuilder state

How did you test this change?

  • Test(s) added
  • Manual testing (please provide screenshots/recordings)
  • No testing (please provide an explanation)

Group by:
GroupByQuery

Group by with multiple columns:
MultiGroupByQuery

Group by with pre-filter:
PreFilter

Group by with post-filter:
PostFilter

Group by with pre-filter and post-filter:
PreFilterAndPostFilter

Copy link

changeset-bot bot commented Feb 12, 2025

🦋 Changeset detected

Latest commit: 495c377

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@finos/legend-graph Patch
@finos/legend-query-builder Patch
@finos/legend-application-data-cube Patch
@finos/legend-application-pure-ide Patch
@finos/legend-application-query-bootstrap Patch
@finos/legend-application-query Patch
@finos/legend-application-repl Patch
@finos/legend-application-studio-bootstrap Patch
@finos/legend-application-studio Patch
@finos/legend-code-editor Patch
@finos/legend-data-cube Patch
@finos/legend-extension-assortment Patch
@finos/legend-extension-dsl-data-quality Patch
@finos/legend-extension-dsl-data-space-studio Patch
@finos/legend-extension-dsl-data-space Patch
@finos/legend-extension-dsl-diagram Patch
@finos/legend-extension-dsl-persistence Patch
@finos/legend-extension-dsl-service Patch
@finos/legend-extension-dsl-text Patch
@finos/legend-extension-store-flat-data Patch
@finos/legend-extension-store-relational Patch
@finos/legend-extension-store-service-store Patch
@finos/legend-lego Patch
@finos/legend-vscode-extension-dependencies Patch
@finos/legend-application-data-cube-bootstrap Patch
@finos/legend-application-pure-ide-deployment Patch
@finos/legend-application-query-deployment Patch
@finos/legend-application-repl-deployment Patch
@finos/legend-application-studio-deployment Patch
@finos/legend-application-data-cube-deployment Patch
@finos/legend-server-showcase-deployment Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 91.07612% with 68 lines in your changes missing coverage. Please review.

Project coverage is 46.23%. Comparing base (82ea08b) to head (495c377).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...pureGraph/from/V1_ValueSpecificationTransformer.ts 0.00% 22 Missing ⚠️
...ery-builder/src/stores/QueryBuilderStateBuilder.ts 67.50% 13 Missing ⚠️
...gation/QueryBuilderTypedAggregationStateBuilder.ts 95.65% 11 Missing ⚠️
...pure/v1/V1_QueryValueSpecificationBuilderHelper.ts 96.41% 8 Missing ⚠️
...QueryBuilderProjectionValueSpecificationBuilder.ts 54.54% 5 Missing ⚠️
...QueryBuilderRelationAggregationValueSpecBuilder.ts 97.95% 4 Missing ⚠️
...tion/changeDetection/ValueSpecificationObserver.ts 0.00% 3 Missing ⚠️
...e/valueSpecification/RelationValueSpecification.ts 0.00% 1 Missing ⚠️
...jection/QueryBuilderTypedProjectionStateBuilder.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3892      +/-   ##
==========================================
- Coverage   46.41%   46.23%   -0.18%     
==========================================
  Files        2255     2264       +9     
  Lines      394495   397131    +2636     
  Branches    11894    17236    +5342     
==========================================
+ Hits       183086   183612     +526     
- Misses     210743   212529    +1786     
- Partials      666      990     +324     
Files with missing lines Coverage Δ
...l/pure/QueryBuilder_PureProtocolProcessorPlugin.ts 87.84% <100.00%> (ø)
...ry-builder/src/graph/QueryBuilderMetaModelConst.ts 100.00% <100.00%> (ø)
...ion/QueryBuilderRelationProjectValueSpecBuilder.ts 81.95% <ø> (ø)
...e/valueSpecification/RelationValueSpecification.ts 39.53% <0.00%> (-0.47%) ⬇️
...jection/QueryBuilderTypedProjectionStateBuilder.ts 99.01% <87.50%> (+0.96%) ⬆️
...tion/changeDetection/ValueSpecificationObserver.ts 0.00% <0.00%> (ø)
...QueryBuilderRelationAggregationValueSpecBuilder.ts 97.95% <97.95%> (ø)
...QueryBuilderProjectionValueSpecificationBuilder.ts 86.60% <54.54%> (-0.69%) ⬇️
...pure/v1/V1_QueryValueSpecificationBuilderHelper.ts 95.09% <96.41%> (+0.20%) ⬆️
...gation/QueryBuilderTypedAggregationStateBuilder.ts 95.65% <95.65%> (ø)
... and 2 more

... and 196 files with indirect coverage changes

@travisstebbins travisstebbins marked this pull request as ready for review February 14, 2025 19:52
@travisstebbins travisstebbins requested a review from a team as a code owner February 14, 2025 19:52
Copy link
Contributor

@akphi akphi left a comment

Choose a reason for hiding this comment

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

Nice job! The tests and general flow are very comprehensive.

I left some minor comments, mostly on some edge cases handling and code organization.

} from '@finos/legend-graph';
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../graph/QueryBuilderMetaModelConst.js';

export const getNumericAggregateOperatorReturnType = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move away from having methods like this:

  1. It doesn't really save you much time code writing, we don't use this anywhere else other than within the operator
  2. The operator code is supposed to be modular, the current flow favors organizing the handling logic for the operator within the same file as the operator rather than dispersing them in classifier method like this ~~ think about why we don't have a giant method with big switch cases to handle all operators but have each file for one operator, the same logic holds true in that case

Copy link
Contributor Author

@travisstebbins travisstebbins Feb 18, 2025

Choose a reason for hiding this comment

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

Makes sense! I removed the function and also removed us trying to manually get the column's return type when we convert from protocol to a SimpleFunctionExpression. Instead, we now update the groupBy() expression's return type when we process the graph here: https://github.com/finos/legend-studio/pull/3892/files#diff-2e5035c76b375d2a795ff0ba9a702405c2dec6dc4e0aabc1d115c63e659db6e3R144

QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_GROUP_BY,
)
QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_GROUP_BY,
])
) {
return V1_buildGroupByFunctionExpression(
Copy link
Contributor

Choose a reason for hiding this comment

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

So an edge case, let's pass the functionName to V1_buildGroupByFunctionExpression
When the functionName is fully specified, i.e. meta::pure::tds::groupBy or meta::pure::functions::relation::groupBy we also know exactly what to handle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. functionName was already passed to V1_buildGroupByFunctionExpression, but now in V1_buildGroupByFunctionExpression I check if functionName === QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_GROUP_BY and call V1_buildTypedGroupByFunctionExpression if that is true.

this.queryBuilderState,
this.parentLambda,
);
if (isTypedGroupByExpression(valueSpecification)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment here, we should be careful of the case where people specify the fully specified function path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I updated isTypedGroupByExpression to first check if expression.functionName === QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_GROUP_BY. I also updated the isTypedProjectionExpression function to do the same.

@akphi akphi merged commit db7ebfb into finos:master Feb 18, 2025
16 checks passed
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