Skip to content

Commit

Permalink
Support relation window functions usage in model queries (finos#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-ssh16 authored Sep 26, 2024
1 parent 832abfe commit 0402379
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function meta::pure::router::routing::processLambda(i:InstanceValue[1], routed:E
f:FunctionDefinition<Any>[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));,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,32 @@ function <<PCT.test>> meta::pure::functions::relation::tests::composition::test_
' qw,9\n'+
'#', $res->sort(~str->ascending())->toString());
}

function <<PCT.test>> meta::pure::functions::relation::tests::composition::testWindowFunctionsAfterProject<T|m>(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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0402379

Please sign in to comment.