From 0402379884174377cbf57f300fc7115fe439c13a Mon Sep 17 00:00:00 2001 From: Sai Sriharsha Annepu <72639930+gs-ssh16@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:37:13 +0530 Subject: [PATCH] Support relation window functions usage in model queries (#3127) --- .../pure/router/routing/router_routing.pure | 2 +- .../relation/tests/composition.pure | 29 +++++++++++++++++++ .../Test_JAVA_RelationFunction_PCT.java | 3 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure index 305771c1e5..d604fd61e1 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure @@ -511,7 +511,7 @@ function meta::pure::router::routing::processLambda(i:InstanceValue[1], routed:E f:FunctionDefinition[1]| if($state.shouldBeRouted, |$func->functionType().parameters->evaluateAndDeactivate()->map( p | let class = $p.genericType.rawType; - if (!$class->toOne()->instanceOf(DataType) && $class != TDSRow && $class != meta::pure::functions::math::wavgUtility::WavgRowMapper && (!$class->toOne()->instanceOf(RelationType)), + if (!$class->toOne()->instanceOf(DataType) && $class != TDSRow && $class != meta::pure::functions::math::wavgUtility::WavgRowMapper && (!$class->toOne()->instanceOf(RelationType)) && ($class != meta::pure::metamodel::relation::Relation) && ($class != meta::pure::functions::relation::_Window), | let map = $routed->filter(v|$v->evaluateAndDeactivate().value.genericType.rawType->toOne()->_subTypeOf($class->toOne());); assert(!$map->isEmpty(),| 'Error mapping not found for class '+$class.name->toOne()+' cache:\''+$routed->cast(@meta::pure::router::store::metamodel::StoreMappingRoutedValueSpecification).sets.class.name->joinStrings(', ')+'\''); pair($p.name, $map->at(0)->cast(@Any));, diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-functions-relation/legend-engine-pure-functions-relation-pure/src/main/resources/core_functions_relation/relation/tests/composition.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-functions-relation/legend-engine-pure-functions-relation-pure/src/main/resources/core_functions_relation/relation/tests/composition.pure index a56c220861..5a480a4554 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-functions-relation/legend-engine-pure-functions-relation-pure/src/main/resources/core_functions_relation/relation/tests/composition.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-functions-relation/legend-engine-pure-functions-relation-pure/src/main/resources/core_functions_relation/relation/tests/composition.pure @@ -376,3 +376,32 @@ function <> meta::pure::functions::relation::tests::composition::test_ ' qw,9\n'+ '#', $res->sort(~str->ascending())->toString()); } + +function <> meta::pure::functions::relation::tests::composition::testWindowFunctionsAfterProject(f:Function<{Function<{->T[m]}>[1]->T[m]}>[1]):Boolean[1] +{ + let expr = {| + [ + ^PersonTypeForCompositionTests(firstName = 'Peter', lastName = 'Smith'), + ^PersonTypeForCompositionTests(firstName = 'Peter', lastName = 'Johnson'), + ^PersonTypeForCompositionTests(firstName = 'Peter', lastName = 'Hill'), + ^PersonTypeForCompositionTests(firstName = 'Anthony', lastName = 'Allen'), + ^PersonTypeForCompositionTests(firstName = 'Anthony', lastName = 'Roberts') + ]->project(~[ + first : x | $x.firstName, + last : x | $x.lastName + ]) + ->extend(over(~first, ~last->ascending()), ~[leadLast:{p,w,r|$p->lead($r).last}, lagLast:{p,w,r|$p->lag($r).last}]) + ->sort([ascending(~first), ascending(~last)]); + }; + + let res = $f->eval($expr); + + assertEquals( '#TDS\n'+ + ' first,last,leadLast,lagLast\n'+ + ' Anthony,Allen,Roberts,null\n'+ + ' Anthony,Roberts,null,Allen\n'+ + ' Peter,Hill,Johnson,null\n'+ + ' Peter,Johnson,Smith,Hill\n'+ + ' Peter,Smith,null,Johnson\n'+ + '#', $res->toString()); +} diff --git a/legend-engine-xts-java/legend-engine-xt-javaPlatformBinding-PCT/src/test/java/org/finos/legend/engine/pure/code/core/java/binding/Test_JAVA_RelationFunction_PCT.java b/legend-engine-xts-java/legend-engine-xt-javaPlatformBinding-PCT/src/test/java/org/finos/legend/engine/pure/code/core/java/binding/Test_JAVA_RelationFunction_PCT.java index c1e06ec368..a48b2d7ec2 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaPlatformBinding-PCT/src/test/java/org/finos/legend/engine/pure/code/core/java/binding/Test_JAVA_RelationFunction_PCT.java +++ b/legend-engine-xts-java/legend-engine-xt-javaPlatformBinding-PCT/src/test/java/org/finos/legend/engine/pure/code/core/java/binding/Test_JAVA_RelationFunction_PCT.java @@ -129,7 +129,8 @@ public class Test_JAVA_RelationFunction_PCT extends PCTReportConfiguration one("meta::pure::functions::relation::tests::composition::test_Extend_Filter_Select_GroupBy_Pivot_Extend_Sort_Limit_Function_1__Boolean_1_", "\"meta::pure::functions::relation::pivot_Relation_1__ColSpecArray_1__AggColSpecArray_1__Relation_1_ is not supported yet!\""), one("meta::pure::functions::relation::tests::composition::test_Distinct_GroupBy_Filter_Function_1__Boolean_1_", "\"meta::pure::functions::relation::filter_Relation_1__Function_1__Relation_1_ is not supported yet!\""), one("meta::pure::functions::relation::tests::composition::test_GroupBy_Distinct_Filter_Function_1__Boolean_1_", "\"meta::pure::functions::relation::filter_Relation_1__Function_1__Relation_1_ is not supported yet!\""), - one("meta::pure::functions::relation::tests::composition::test_GroupBy_Filter_Function_1__Boolean_1_", "\"meta::pure::functions::relation::filter_Relation_1__Function_1__Relation_1_ is not supported yet!\"") + one("meta::pure::functions::relation::tests::composition::test_GroupBy_Filter_Function_1__Boolean_1_", "\"meta::pure::functions::relation::filter_Relation_1__Function_1__Relation_1_ is not supported yet!\""), + one("meta::pure::functions::relation::tests::composition::testWindowFunctionsAfterProject_Function_1__Boolean_1_", "\"meta::pure::functions::relation::sort_Relation_1__SortInfo_MANY__Relation_1_ is not supported yet!\"") ); public static Test suite()