Skip to content

Commit

Permalink
add testWrapper Example
Browse files Browse the repository at this point in the history
  • Loading branch information
AFine-gs committed Oct 31, 2024
1 parent 14a6f84 commit 66095a3
Showing 1 changed file with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2024 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.

###Pure
import meta::pure::lineage::*;
import meta::analytics::lineage::*;
import meta::relational::tests::model::simple::*;
import meta::relational::tests::mapping::association::embedded::*;
function meta::pure::lineage::test::testPersonToOrganisationsExample():Boolean[1]
{
meta::relational::tests::mapping::association::embedded::setUp();
let result = testWrapper(|Person.all()->project([p|$p.lastName,p|$p.firm.legalName, p|$p.firm.organizations.name], ['name', 'firm', 'team']), associationMapping, meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions());
let lineage = $result->meta::pure::lineage::test::getLineage();
assertLineage(['Lambda', 'db_myDB', 'tb_myDBdefaultORGANIZATIONS', 'tb_myDBdefaultPERSON_FIRM_DENORM'], ['Lambda', 'meta::relational::tests::model::simple::Firm', 'meta::relational::tests::model::simple::Organization', 'meta::relational::tests::model::simple::Person', 'pack_meta::relational::tests::model::simple'],'[firm: [PERSON_FIRM_DENORM.FIRM_LEGALNAME <TableAliasColumn>], name: [PERSON_FIRM_DENORM.PERSON_LASTNAME <TableAliasColumn>], team: [ORGANIZATIONS.FIRM_ID <JoinTreeNode>, ORGANIZATIONS.NAME <TableAliasColumn>, PERSON_FIRM_DENORM.FIRM_ID <JoinTreeNode>]]',$lineage);
let tds= $result->getTabularDatasetResult().values->at(0);
assertEquals(5, $tds.rows->size());
assertSameElements(['Smith Firm X Team 1', 'Smith Firm X Team 2', 'Johnson Firm X Team 1', 'Johnson Firm X Team 2', 'Roberts Firm A Team 3'], $tds.rows->map(r|$r.getString('name')+' '+$r.getString('firm')->toString()+ ' ' +$r.getString('team')));
}



###Pure
import meta::analytics::lineage::*;
import meta::core::runtime::*;
import meta::pure::mapping::*;
import meta::pure::lineage::test::*;
function meta::pure::lineage::test::getLineage(result:Map<String,meta::pure::lineage::test::Result>[1]):FunctionAnalytics[1]
{
$result->get('lineage')->cast(@LineageResult).result->toOne();

}

function meta::pure::lineage::getTabularDatasetResult(result:Map<String,meta::pure::lineage::test::Result>[1]):meta::pure::mapping::Result<TabularDataSet|*>[1]
{
$result->get('executeResult')->cast(@ExecuteResult<TabularDataSet>).result->toOne();

}

function meta::pure::lineage::testWrapper<T|y>(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Map<String,meta::pure::lineage::test::Result>[1]
{

newMap([meta::pure::lineage::test::executeWrapper($f,$m,$runtime,$extensions),
meta::pure::lineage::test::lineageWrapper($f,$m,$runtime,$extensions)
]
);

}


function meta::pure::lineage::test::executeWrapper<T|y>(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Pair<String,meta::pure::lineage::test::Result>[1]
{

pair('executeResult',^ExecuteResult<T>(result=meta::pure::router::execute($f,$m,$runtime,$extensions)));

}

function meta::pure::lineage::test::lineageWrapper<T|y>(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Pair<String,meta::pure::lineage::test::Result>[1]
{

pair('lineage',^LineageResult(result=computeLineage($f,$m,$runtime,$extensions)));

}


Class meta::pure::lineage::test::Result
{

}

Class meta::pure::lineage::test::ExecuteResult<T> extends meta::pure::lineage::test::Result
{
result:meta::pure::mapping::Result<T|*>[1];

}
Class meta::pure::lineage::test::LineageResult extends meta::pure::lineage::test::Result
{
result:FunctionAnalytics[1];
}

0 comments on commit 66095a3

Please sign in to comment.