Support sub-aggregation queries (correlated subqueries with GROUP BY) for Relation Function Class Mappings#4844
Merged
Merged
Conversation
…feature-class_to_relation-union_mapping_support
…r fixes and #SQL instance pk resolution
…feature-class_to_relation-subagg_pk-support # Conflicts: # legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ClassMappingPrerequisiteElementsPassBuilder.java # legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/mapping/RelationFunctionMappingParseTreeWalker.java # legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/parser/TestMappingGrammarParser.java # legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/packageableElement/mapping/relationFunction/RelationFunctionClassMapping.java # legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/mapping/relationFunctionMapping.pure # legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/helperFunctions/helperFunctions.pure
…ure-class_to_relation-subagg_pk-support # Conflicts: # legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/parser/TestMappingGrammarParser.java
…ure-class_to_relation-subagg_pk-support
…ure-class_to_relation-subagg_pk-support
Support sub-aggregation queries (correlated subqueries with GROUP BY) for Relation Function Class Mappings
gs-rpant1729
previously approved these changes
Jun 12, 2026
Contributor
|
LGTM |
aziemchawdhary-gs
approved these changes
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relation Function Class Mappings currently lack primary key (PK) support, which is required for union mappings, graph fetch, and sub-aggregation queries (e.g., correlated subqueries with GROUP BY). This work adds end-to-end PK support across the compiler stack: Grammar, Parser, Composer, Compiler (prerequisite elements pass + third pass), and Pure inference logic.
Primary keys can be explicitly declared via ~primaryKey syntax or auto-inferred where possible — for example, when the relation function body uses a direct table accessor (#>{my::db.personTable}#), the PK is inferred from the underlying table's primary key. An extension-based architecture (RelationElementAccessorExtension) enables PK inference for SQL expressions (#SQL{...}#) and other store-specific relation sources without coupling modules.
API/Grammar Design:
Single PK: ~primaryKey: ID Multiple PKs: ~primaryKey: [ID, FIRMID] Auto-inferred (no declaration needed): ~func my::personFunc_Relation_1 where the function body resolves to a table accessor