Skip to content

Commit

Permalink
Initial FCT
Browse files Browse the repository at this point in the history
  • Loading branch information
AFine-gs committed Nov 13, 2024
1 parent 01e4528 commit c39700a
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,18 @@ function meta::pure::lineage::analytics::inlineQualifiedProperties(vs: ValueSpec
ve : VariableExpression[1] | let resolved = $ve->resolve($vars, $openVars); if($resolved->isEmpty(), | $ve, | $resolved->toOne());,
v : ValueSpecification[1] | $v
]);
}
}


function meta::pure::lineage::analytics::reportLineageToString(report:meta::pure::lineage::result::ReportLineage[1]):String[1]
{
$report.properties->map(c | $c.propertyName + $c.resultDetail)->sort()->joinStrings('[', ', ', ']');
}

function meta::pure::lineage::test::assertLineage(storeLineage:String[*], classLineage:String[*], reportLineage:String[1], result:meta::pure::lineage::result::LineageResult[1]):Boolean[1]
{

assertSameElements($storeLineage, $result.storeLineage.nodes.data.id) && assertSameElements($classLineage, $result.classLineage.nodes.data.id) && assertEquals($reportLineage, meta::pure::lineage::analytics::reportLineageToString($result.reportLineage));
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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.


Class meta::pure::lineage::report::Source
{
<<equality.Key>> context: String[1];
}

Class meta::pure::lineage::report::PropertySource extends meta::pure::lineage::report::Source
{
<<equality.Key>> classPath: String[1];
<<equality.Key>> propertyName: String[1];
}


Class meta::pure::lineage::graph::Node
{
data : meta::pure::lineage::graph::NodeData[1];
}

Class meta::pure::lineage::graph::NodeData
{
id : String[1];
text : String[1];
type : String[1];
displayType : String[0..1];
parent : meta::pure::lineage::graph::Node[0..1];
}

Class meta::pure::lineage::graph::Edge
{
data : meta::pure::lineage::graph::EdgeData[1];
}

Class meta::pure::lineage::graph::EdgeData
{
id : String[1];
text : String[1];
type : String[1];
source : meta::pure::lineage::graph::Node[1];
target : meta::pure::lineage::graph::Node[1];
}

Class meta::pure::lineage::graph::Graph
{
nodes : meta::pure::lineage::graph::Node[*];
edges : meta::pure::lineage::graph::Edge[*];
}

Class meta::pure::lineage::result::PropertyLineage
{
propertyName : String[1];
resultDetail : String[1];
}

Class meta::pure::lineage::result::ReportLineage
{
properties : meta::pure::lineage::result::PropertyLineage[*];
}


Class meta::pure::lineage::result::LineageResult
{
storeLineage: meta::pure::lineage::graph::Graph[1];
classLineage: meta::pure::lineage::graph::Graph[1];
reportLineage : meta::pure::lineage::result::ReportLineage[1];
}

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.

import meta::core::runtime::*;
import meta::pure::mapping::*;
import meta::pure::test::fct::*;


function

meta::pure::test::fct::executeWrapper<T|y>(f:FunctionDefinition<{->T[y]}>[1],holder:meta::pure::test::fct::TestParameters[1]):meta::pure::test::fct::ExecuteResult<T>[1]
{
^ExecuteResult<T>(result=meta::pure::router::execute($f,$holder.mapping,$holder.runtime,$holder.context,$holder.extensions));
}


Class meta::pure::test::fct::TestResult
{

}

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

}

function meta::pure::test::fct::assertTDSExecuteResult<T>(result:meta::pure::test::fct::TestResult[1],assertion:Function<{meta::pure::mapping::Result<T|*>[1]->Boolean[1]}>[1]):Boolean[1]
{

if($result->instanceOf(ExecuteResult),
|let tds = $result->cast(@ExecuteResult<TabularDataSet>).result;
$assertion->eval($tds);,
| true);
}


function meta::pure::test::fct::assertLineageResult(result:meta::pure::test::fct::TestResult[1], storeLineage:String[*], classLineage:String[*], reportLineage:String[1]):Boolean[1]
{

if($result->instanceOf(meta::pure::test::fct::LineageResult),
| let lineage = $result->cast(@meta::pure::test::fct::LineageResult).result;
meta::pure::lineage::test::assertLineage($storeLineage,$classLineage,$reportLineage,$lineage);,
| true);
}

Class meta::pure::test::fct::LineageResult extends meta::pure::test::fct::TestResult
{
result:meta::pure::lineage::result::LineageResult[1];
}


function meta::pure::test::fct::testParameters(mapping:meta::pure::mapping::Mapping[1],runtime:meta::core::runtime::Runtime[1],extensions:meta::pure::extension::Extension[*]):meta::pure::test::fct::TestParameters[1]
{
^meta::pure::test::fct::TestParameters( mapping = $mapping,
runtime = $runtime,
extensions = $extensions,
context = ^meta::pure::runtime::ExecutionContext());
}

function meta::pure::test::fct::testParameters(mapping:meta::pure::mapping::Mapping[1],runtime:meta::core::runtime::Runtime[1],context:meta::pure::runtime::ExecutionContext[1], extensions:meta::pure::extension::Extension[*]):meta::pure::test::fct::TestParameters[1]
{
^meta::pure::test::fct::TestParameters( mapping = $mapping,
runtime = $runtime,
extensions = $extensions,
context = $context);
}



Class meta::pure::test::fct::TestParameters
{
mapping:meta::pure::mapping::Mapping[1];
runtime:meta::core::runtime::Runtime[1];
extensions:meta::pure::extension::Extension[*];
context:meta::pure::runtime::ExecutionContext[1];
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ Class meta::analytics::lineage::PropertyElement
type : String[0..1];
}


// function meta::analytics::lineage::computeTestLineage(f:FunctionDefinition<Any>[1], m:Mapping[1], r:Runtime[0..1], extensions:meta::pure::extension::Extension[*]):meta::pure::lineage::result::LineageResult[1]
// {
// let lineage = meta::analytics::lineage::computeLineage($f,$m,$r,$extensions);
// ^meta::pure::lineage::result::LineageResult(storeLineage=$lineage.databaseLineage,
// classLineage=$lineage.classLineage,
// reportLineage= $lineage.reportLineage->reportLineageToResult() );

// }

// function meta::analytics::lineage::reportLineageToResult(report:ReportLineage[1]):meta::pure::lineage::result::ReportLineage[1]
// {
// ^meta::pure::lineage::result::ReportLineage(properties=$report.columns->map(c | ^meta::pure::lineage::result::PropertyLineage(propertyName=$c.name, resultDetail= $c.columns->map(t|$t.column.owner->cast(@Table).name->toOne()+'.'+$t.column.name->toOne()+' <'+$t.context+'>')->removeDuplicates()->sort()->makeString(': [', ', ', ']'))));
// }


function meta::analytics::lineage::computeLineage(f:FunctionDefinition<Any>[1], m:Mapping[1], r:Runtime[0..1], extensions:meta::pure::extension::Extension[*]):FunctionAnalytics[1]
{
let mappings = if($r->isEmpty(), |$m, |$m->concatenate(getMappingsFromRuntime($r->toOne())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,6 @@ function <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly
['my::test::testSemiStructuredMappingQuery__TabularDataSet_1_','my::model::Person','my::model::Firm','pack_my::model'],
'[employeeName: [PersonTable.PERSON_DETAILS <DynaFunction>], firmName: [FirmTable.ID <JoinTreeNode>, FirmTable.LEGAL_NAME <TableAliasColumn>, PersonTable.PERSON_DETAILS <JoinTreeNode>]]',
$lineage);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,18 @@ function meta::relational::mapping::findMainClassInGetAllExpression(vs:ValueSpec
let getAllFe = $vs->findExpressionsForFunctionInValueSpecification([getAll_Class_1__T_MANY_, getAll_Class_1__Date_1__T_MANY_, getAll_Class_1__Date_1__Date_1__T_MANY_]);
if($getAllFe->isEmpty(), | Any, | $getAllFe.parametersValues->at(0)->cast(@ExtendedRoutedValueSpecification)->byPassRouterInfo()->cast(@InstanceValue).values->toOne()->cast(@Class<Any>));
}



function meta::relational::mapping::assertTDS(result:meta::pure::test::fct::TestResult[1],expected:meta::pure::metamodel::relation::TDS<Any>[1]):Boolean[1]
{

if($result->instanceOf(meta::pure::test::fct::ExecuteResult),
|let tds = $result->cast(@meta::pure::test::fct::ExecuteResult<TabularDataSet>).result;
$expected.csv->println();
$tds.values->toOne()->toCSV()->println();
// assertSameElements($expected.csv, $tds.values->toOne()->toCSV());,
true;,

| true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::relational::mapping::*;
import meta::pure::test::fct::*;
import meta::relational::tests::*;
import meta::external::store::relational::tests::*;
import meta::pure::profiles::*;
Expand All @@ -30,13 +32,30 @@ function <<test.BeforePackage>> meta::relational::tests::mapping::association::e
}



function <<test.Test>> meta::relational::tests::mapping::association::embedded::testPersonToOrganisations():Boolean[1]
function <<FCT.test>> meta::relational::tests::mapping::association::embedded::testEmbbeddedAssociation<T>(f:Function<{FunctionDefinition<T>[1],TestParameters[1]->TestResult[1]}>[1]):Boolean[1]
{
let result1 = execute(|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()).values->at(0);
assertEquals(5, $result1.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'], $result1.rows->map(r|$r.getString('name')+' '+$r.getString('firm')->toString()+ ' ' +$r.getString('team')));
}
let fn = {|Person.all()->project([p|$p.lastName,p|$p.firm.legalName, p|$p.firm.organizations.name], ['name', 'firm', 'team'])};
let parameters = meta::pure::test::fct::testParameters( associationMapping, meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions());
let fctResult = $f->eval($fn,$parameters);
let expectedTDS =
#TDS
name, firm, team
Smith, Firm, X Team 1
Smith, Firm X, Team 2
Johnson, Firm X, Team 1
Roberts, Firm A, Team 3#;

assertTDS($fctResult,$expectedTDS);

assertLineageResult($fctResult,['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>]]');


}




function <<test.Test>> meta::relational::tests::mapping::association::embedded::testFirmToOrganisations():Boolean[1]
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

<properties>
<!-- Legend -->
<legend.pure.version>5.22.0</legend.pure.version>
<legend.pure.version>5.22.2-SNAPSHOT</legend.pure.version>
<legend.shared.version>0.25.7</legend.shared.version>
<legend.web-application.version>12.59.0</legend.web-application.version>

Expand Down

0 comments on commit c39700a

Please sign in to comment.