Skip to content

Commit

Permalink
lineage support for mappingExtensions (#3161)
Browse files Browse the repository at this point in the history
  • Loading branch information
AFine-gs authored Oct 8, 2024
1 parent fbcbc42 commit 65273d1
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,17 @@ function meta::pure::mapping::allEnumerationMappings(m: Mapping[1]): Enumeration
$m.enumerationMappings->concatenate($m.includes->map(i | $i.included->allEnumerationMappings()))
}










function meta::pure::mapping::allSuperSetImplementations(set :PropertyMappingsImplementation[1], m:Mapping[1]):PropertyMappingsImplementation[*]
{
if ($set.superSetImplementationId->isEmpty(),
| [],
| let superMapping = $m->classMappingById($set.superSetImplementationId->toOne());
if($superMapping->isEmpty(),
| [],
|$superMapping->toOne()->cast(@PropertyMappingsImplementation)->allSuperSetImplementations($m)->concatenate($superMapping->toOne()->cast(@PropertyMappingsImplementation))
);
);
}

function meta::pure::router::clustering::resolveInstanceSetImplementations(o:OperationSetImplementation[1]):InstanceSetImplementation[*]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ function meta::analytics::lineage::flowDatabase::toFlowDatabase(p:PropertyPathTr
,
cl: Class<Any>[1]|if($disregardClass,
|meta::analytics::lineage::flowDatabase::manageQualifiers($p.children, $extraChildren)->map(c|$c->toFlowDatabase($m, $sets, false, $extraChildren)),
|meta::analytics::lineage::flowDatabase::manageQualifiers($p.children, $extraChildren)->map(c|$c->toFlowDatabase($m, $m->rootClassMappingByClass($cl)->last()->meta::pure::router::routing::resolveOperation($m), false, $extraChildren));
|
let sets = $m->_classMappingByClass($cl)->map(s|$s->meta::pure::router::routing::resolveOperation($m));
let setsWithSuper = $sets->map(s|$s->allSuperSetImplementations($m))->concatenate($sets)->cast(@InstanceSetImplementation);
meta::analytics::lineage::flowDatabase::manageQualifiers($p.children, $extraChildren)->map(c|$c->toFlowDatabase($m, $setsWithSuper, false, $extraChildren));
);,
a :Any[1]|meta::analytics::lineage::flowDatabase::manageQualifiers($p.children, $extraChildren)->map(c|$c->toFlowDatabase($m, $sets, $disregardClass, $extraChildren))
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,29 @@ function <<test.Test>> meta::analytics::lineage::tests::relational::graphFetch::

let mapping = meta::relational::graphFetch::tests::union::propertyLevel::Mapping6;

let runtime = meta::external::store::relational::tests::testRuntime();let lineage = meta::analytics::lineage::computeLineage($query, $mapping, $runtime, meta::relational::extension::relationalExtensions());
let runtime = meta::external::store::relational::tests::testRuntime();

let lineage = meta::analytics::lineage::computeLineage($query, $mapping, $runtime, meta::relational::extension::relationalExtensions());

meta::analytics::lineage::assertLineage(['Lambda', 'db_myDB', 'tb_myDBdefaultAddressSet1', 'tb_myDBdefaultAddressSet2', 'tb_myDBdefaultAddressSet3', 'tb_myDBdefaultFirmSet1', 'tb_myDBdefaultFirmSet2', 'tb_myDBdefaultFirmSet3', 'tb_myDBdefaultPersonSet1', 'tb_myDBdefaultPersonSet2', 'tb_myDBdefaultPersonSet3'],
['Lambda', 'meta::relational::tests::model::simple::Address', 'meta::relational::tests::model::simple::Firm', 'meta::relational::tests::model::simple::Person', 'pack_meta::relational::tests::model::simple'],
'[Firm.employees.address.name: [AddressSet1.ID <JoinTreeNode>, AddressSet1.name <TableAliasColumn>, AddressSet2.ID <JoinTreeNode>, AddressSet2.name <TableAliasColumn>, AddressSet3.ID <JoinTreeNode>, AddressSet3.name <TableAliasColumn>, FirmSet1.ID <JoinTreeNode>, FirmSet2.ID <JoinTreeNode>, FirmSet3.ID <JoinTreeNode>, PersonSet1.ADDRESSID <JoinTreeNode>, PersonSet1.FirmID <JoinTreeNode>, PersonSet2.ADDRESSID <JoinTreeNode>, PersonSet2.FirmID <JoinTreeNode>, PersonSet3.ADDRESSID <JoinTreeNode>, PersonSet3.FirmID <JoinTreeNode>], Firm.employees.lastName: [FirmSet1.ID <JoinTreeNode>, FirmSet2.ID <JoinTreeNode>, FirmSet3.ID <JoinTreeNode>, PersonSet1.FirmID <JoinTreeNode>, PersonSet1.lastName_s1 <TableAliasColumn>, PersonSet2.FirmID <JoinTreeNode>, PersonSet2.lastName_s2 <TableAliasColumn>, PersonSet3.FirmID <JoinTreeNode>, PersonSet3.lastName_s3 <TableAliasColumn>], Firm.legalName: [FirmSet1.name <TableAliasColumn>, FirmSet2.name <TableAliasColumn>, FirmSet3.name <TableAliasColumn>]]',
$lineage);
}

###Pure
import meta::analytics::lineage::*;
import meta::pure::lineage::scanRelations::*;

function <<meta::pure::profiles::test.Test>> meta::analytics::lineage::tests::relational::test::testMilestoneInheriteance():Boolean[1]
{
let query = {| meta::relational::tests::milestoning::ProductWithConstraint1.all(%2022-02-02)-> project([f|$f.ascPnL.pnl], ['OrderID'])};
let mapping = meta::relational::tests::milestoning::milestoningmapWithMappingExtensions;

let lineage = meta::analytics::lineage::computeLineage($query, $mapping,meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions());
meta::analytics::lineage::assertLineage(['Lambda', 'db_dbInclusion', 'db_dbWithInclusion', 'tb_dbInclusiondefaultProductTable', 'tb_dbWithInclusiondefaultOrderTable'],
['Lambda', 'meta::relational::tests::milestoning::OrderPnl', 'meta::relational::tests::milestoning::ProductWithConstraint1', 'pack_meta::relational::tests::milestoning'],
'[OrderID: [OrderTable.pnl <TableAliasColumn>, OrderTable.prodFk <JoinTreeNode>, ProductTable.id <JoinTreeNode>]]',
$lineage);
}

Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ function <<access.private>> meta::pure::lineage::scanColumns::scanColumns(p:Prop
cl: Class<Any>[1]|
print(if($debug.debug,|$debug.space+'Process Class: '+$cl.name->toOne()+'\n',|''));
if($isRoot,
|
let nClassToSets = if($classToSets->keys()->contains($cl), |$classToSets, | $classToSets->keyValues()->concatenate(pair($cl, list($m->_classMappingByClass($cl)->map(s|$s->resolveOperation($m)))))->newMap());
| let sets = $m->_classMappingByClass($cl)->map(s|$s->resolveOperation($m));
let setsWithSuper = $sets->map(s|$s->meta::pure::mapping::allSuperSetImplementations($m))->concatenate($sets)->cast(@InstanceSetImplementation);
let nClassToSets = if($classToSets->keys()->contains($cl), |$classToSets, | $classToSets->keyValues()->concatenate(pair($cl, list($setsWithSuper)))->newMap());
let nsets = $nClassToSets->get($cl).values;
$p.children->map(c|$c->scanColumns($m, $sets->concatenate($nsets)->removeDuplicatesBy(x | $x.id), $nClassToSets, $idToSet, false, ^$debug(space=$debug.space+' ')));,
$p.children->map(c|$c->scanColumns($m, $setsWithSuper->concatenate($nsets)->removeDuplicatesBy(x | $x.id), $nClassToSets, $idToSet, false, ^$debug(space=$debug.space+' ')));,
|
$p.children->map(c|$c->scanColumns($m, $sets, $classToSets, $idToSet, false, ^$debug(space=$debug.space+' '))););,
a :Any[1]|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,59 @@ Mapping meta::relational::tests::milestoning::viewFilter::MilestoningWithFilters
}
)

###Mapping
import meta::relational::tests::milestoning::*;
Mapping meta::relational::tests::milestoning::milestoningmapWithMappingExtensionsInc
(

meta::relational::tests::milestoning::ProductWithConstraint1[product1] extends [product]: Relational{
val : [dbInclusion]ProductTable.name
}

meta::relational::tests::milestoning::Product[product] : Relational{
id : [dbInclusion]ProductTable.id
}

)


Mapping meta::relational::tests::milestoning::milestoningmapWithMappingExtensions
(
include meta::relational::tests::milestoning::milestoningmapWithMappingExtensionsInc[dbInclusion->dbWithInclusion]

meta::relational::tests::milestoning::OrderPnl[order] : Relational{
pnl : [dbWithInclusion]OrderTable.pnl
}

meta::relational::tests::milestoning::OrderPNLProduct: Relational
{
AssociationMapping
(
ascPnL[product,order] : [dbWithInclusion]@Order_Product,
ascProduct[order,product] : [dbWithInclusion]@Order_Product
)

}

)

###Relational
Database meta::relational::tests::milestoning::dbWithInclusion(
include meta::relational::tests::milestoning::dbInclusion

Table OrderTable(id Integer PRIMARY KEY, orderDate DATE, prodFk Integer, pnl Integer)
Join Order_Product(OrderTable.prodFk=ProductTable.id)

)


###Relational
Database meta::relational::tests::milestoning::dbInclusion(

Table ProductTable(id Integer PRIMARY KEY, orderDate DATE, name VARCHAR(255), prodFk Integer)
)


###Relational
Database meta::relational::tests::milestoning::ViewChainDb
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Class <<temporal.businesstemporal>> meta::relational::tests::milestoning::Produc
)
]
{
val:String[0..1];
}

Class <<temporal.businesstemporal>> meta::relational::tests::milestoning::ProductWithConstraint1b extends meta::relational::tests::milestoning::Product
Expand Down Expand Up @@ -299,6 +300,11 @@ Association meta::relational::tests::milestoning::OrderProduct{
orders : Order[*];
}

Association meta::relational::tests::milestoning::OrderPNLProduct{
ascProduct : Product[1];
ascPnL : OrderPnl[1];
}

Class <<temporal.businesstemporal>> meta::relational::tests::milestoning::inheritance::VehicleOwner
{
vehicles : Vehicle[*];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ function <<test.Test>> meta::relational::tests::mapping::extend::mainTable::test
let superMappingMainTable = B2Mapping->classMappingById('b2')->cast(@RootRelationalInstanceSetImplementation)->map(x|$x->mainTable());
assertEquals($superMappingMainTable, $mainTable);
}


function <<test.Test>> meta::relational::tests::mapping::extend::mainTable::testSuperSetIdsAreCollected():Any[*]
{
let sets = meta::pure::mapping::allSuperSetImplementations( meta::relational::tests::mapping::extend::mainTable::C1Mapping->classMappingById('c1')->toOne()->cast(@PropertyMappingsImplementation),meta::relational::tests::mapping::extend::mainTable::C1Mapping);
assertSameElements(['a','b1'],$sets.id);

}

0 comments on commit 65273d1

Please sign in to comment.