
platform_functions_relation.relation.functions.join.pure Maven / Gradle / Ivy
// Copyright 2023 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import meta::pure::test::pct::*;
import meta::pure::metamodel::relation::*;
Enum meta::pure::functions::relation::JoinKind
{
LEFT,
INNER
}
native function <> meta::pure::functions::relation::join(rel1:Relation[1], rel2:Relation[1], joinKind:JoinKind[1], f:Function<{T[1],V[1]->Boolean[1]}>[1]):Relation[1];
function <> meta::pure::functions::relation::tests::join::testSimpleJoinShared(f:Function<{Function<{->T[m]}>[1]->T[m]}>[1]):Boolean[1]
{
let tds = #TDS
id, name
1, George
2, Pierre
3, Sachin
4, David
#;
let tds2 = #TDS
id2, col, other
1, More George 1, 1
1, More George 2, 2
4, More David, 1
#;
let expr = {|$tds->join($tds2, JoinKind.INNER, {x,y| $x.id == $y.id2})};
let res = $f->eval($expr);
assertEquals( '#TDS\n'+
' id,name,id2,col,other\n'+
' 1,George,1,More George 1,1\n'+
' 1,George,1,More George 2,2\n'+
' 4,David,4,More David,1\n'+
'#', $res->sort([~id->ascending(),~col->ascending()])->toString());
let expr2 = {|$tds->join($tds2, JoinKind.LEFT, {x,y| $x.id == $y.id2})};
let res2 = $f->eval($expr2);
assertEquals( '#TDS\n'+
' id,name,id2,col,other\n'+
' 1,George,1,More George 1,1\n'+
' 1,George,1,More George 2,2\n'+
' 2,Pierre,null,null,null\n'+
' 3,Sachin,null,null,null\n'+
' 4,David,4,More David,1\n'+
'#', $res2->sort([~id->ascending(),~col->ascending()])->toString());
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy