Skip to content

Commit

Permalink
milestoning
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujgirdhar committed Nov 25, 2023
1 parent 5bc1ee3 commit 7ea5283
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function meta::pure::graphFetch::routing::propertyMappingInfo(prop: PropertyGrap
let fe = $routedProperty->byPassRouterInfo()->cast(@FunctionExpression);
let sourceSets = if($prop.subType->isEmpty(), | $fe, | $fe.parametersValues->evaluateAndDeactivate()->at(0)->byPassRouterInfo()->cast(@FunctionExpression)).parametersValues->evaluateAndDeactivate()->at(0)->cast(@StoreMappingRoutedValueSpecification).sets->resolveOperation($mapping)->cast(@InstanceSetImplementation);
$sourceSets->map({ss |
let propMaps = $ss->propertyMappingsByPropertyName($property.name->toOne())->filter(x | $x.targetSetImplementationId->in($targetSets.id));
let propMaps = $ss->_propertyMappingsByPropertyName($property.name->toOne())->filter(x | $x.targetSetImplementationId->in($targetSets.id));
$propMaps->map(pm | $mapping->classMappingById($pm.targetSetImplementationId)->resolveOperation($mapping)->map(ts | ^$pm(targetSetImplementationId = $ts.id)));
});,
| $propertyMappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function meta::pure::router::store::routing::build(v:ValueSpecification[1], l:Li
|$s->cast(@InstanceSetImplementation)->meta::pure::mapping::propertyMappingsByPropertyName($propertyName),
|$resWithAssoc);

let withOtherwise = if($res->isEmpty(), // for graphFetch flow, the parent set gets resolved to the otherwiseProperty mapping always.
| let byName = $s->cast(@InstanceSetImplementation)->meta::pure::mapping::propertyMappingsByPropertyName($propertyName)->filter(pm|$pm->instanceOf(OtherwiseEmbeddedSetImplementation))->map(pm|$pm->cast(@OtherwiseEmbeddedSetImplementation));
let withOtherwise = if($res->isEmpty() && $f.func->instanceOf(Property), // for graphFetch flow, the parent set gets resolved to the otherwiseProperty mapping always.
| let byName = $s->cast(@InstanceSetImplementation)->meta::pure::mapping::_propertyMappingsByPropertyName($propertyName)->filter(pm|$pm->instanceOf(OtherwiseEmbeddedSetImplementation))->map(pm|$pm->cast(@OtherwiseEmbeddedSetImplementation));
let pms = $byName.otherwisePropertyMapping->filter(pm|$pm.targetSetImplementationId->in($targetIds));
$pms;,
| $res );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function <<access.private>> meta::relational::graphFetch::executionPlan::generat
let res = if ($isQualified,
{|
let newVars = newVarsForMilestoningContext($propTree, $inScopeVars);
let updatedState = ^$pureToSqlState(inGetterFlow = true, qualifierBase=^OperationWithParentPropertyMapping(element = $base), inScopeVars = $pureToSqlState.inScopeVars->putAll($newVars));
let updatedState = ^$pureToSqlState(inGetterFlow = true, milestoningUseOtherwise = true, qualifierBase=^OperationWithParentPropertyMapping(element = $base), inScopeVars = $pureToSqlState.inScopeVars->putAll($newVars));
processQualifiedProperty($propTree.property->cast(@QualifiedProperty<Any>), [], $base, ^Map<VariableExpression, ValueSpecification>(), $updatedState, JoinType.LEFT_OUTER, '_gftq', ^List<ColumnGroup>(), $debug, $extensions).element->cast(@SelectWithCursor);
},
{|
Expand Down Expand Up @@ -796,7 +796,7 @@ function meta::relational::graphFetch::executionPlan::generateNonPrimitiveProper
let newVars = newVarsForMilestoningContext($propTree, $inScopeVars);
let mcForProperty = milestoningContextFromPropertyTree($propTree, $parentTree, $mc, ^$pureToSqlState(inScopeVars = $pureToSqlState.inScopeVars->putAll($newVars)), $debug->indent(), $extensions);
let baseWithMc = ^$base(milestoningContext = $mcForProperty);
let updatedState = ^$pureToSqlState(inGetterFlow = true, qualifierBase = ^OperationWithParentPropertyMapping(element = $baseWithMc), inScopeVars = $pureToSqlState.inScopeVars->putAll($newVars));
let updatedState = ^$pureToSqlState(inGetterFlow = true, milestoningUseOtherwise = true, qualifierBase = ^OperationWithParentPropertyMapping(element = $baseWithMc), inScopeVars = $pureToSqlState.inScopeVars->putAll($newVars));
let withQualifier = processQualifiedProperty($propTree.property->cast(@QualifiedProperty<Any>), [], $baseWithMc, ^Map<VariableExpression, ValueSpecification>(), $updatedState, JoinType.LEFT_OUTER, '_gftq', ^List<ColumnGroup>(), $debug, $extensions).element->cast(@SelectWithCursor);
let newSelect = $withQualifier.select->pushFilters($extensions);
let innerRes = ^$withQualifier(select = ^$newSelect(leftSideOfFilter = []));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,26 @@ function <<test.Test, test.AlloyOnly, test.ToFix>> {serverVersion.start='v1_19_0
$result
);
}

function <<test.Test, test.AlloyOnly, test.ToFix>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::testEmbeddedMappingQualifiedPropertyAccessWithArgs(): Boolean[1]
{
let tree = #{
Person {
firstName,
firm {
legalName,
'employeeByLastNameFirstName': employeeByLastNameFirstName('Smith')
}
}
}#;
let query = {|Person.all()->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::mapping::embedded::model::mapping::testMappingEmbedded;
let runtime = meta::external::store::relational::tests::testRuntime();

let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'{}',
$result
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import meta::relational::tests::mapping::embedded::advanced::model::*;
function <<test.BeforePackage>> meta::relational::graphFetch::tests::embedded::otherwise::setup(): Boolean[1]
{
meta::relational::tests::mapping::embedded::advanced::setUp();
meta::relational::tests::milestoning::initDatabase();
true;
}


function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testOtherwiseEmbeddedMapping(): Boolean[1]
{
let tree = #{
Expand Down Expand Up @@ -234,7 +235,105 @@ import meta::pure::graphFetch::execution::*;
import meta::pure::executionPlan::profiles::*;
import meta::relational::tests::milestoning::*;

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestoning(): Boolean[1]

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestonedPropertyAllVersions(): Boolean[1]
{
let tree = #{
Order {
id,
productAllVersions{
name,
type
}
}
}#;
let query = {|Order.all()->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::milestoning::embedded::otherwiseMapping3;
let runtime = meta::external::store::relational::tests::testRuntime();

let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'[{"id":1, "productAllVersions":[{"name":"ProductName","type":"STOCK"}]},'+
'{"id":2,"productAllVersions":[{"name":"ProductName1","type":"STOCK"},{"name":"ProductName2","type":"STOCK"}]}]',
$result
);
}

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestonedRootWithMilestonedPropertyAllVersions(): Boolean[1]
{
let tree = #{ Product{
id,
name,
synonymsAllVersions{
synonym
}
}}#;
let query = {|Product.all(%2023-10-15T00:00:00)->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::milestoning::embedded::otherwiseMapping3;
let runtime = meta::external::store::relational::tests::testRuntime();

let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'[{"id":2,"name":"ProductName2","synonymsAllVersions":[{"synonym":"GS-Mod-S0"},{"synonym":"GS-Mod-S1"},{"synonym":"GS-Mod-S2"},{"synonym":"GS-Mod-S3"}]},' +
' {"id":3,"name":"ProductName3","synonymsAllVersions":[]}]',
$result
);
}

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestonedRootAndMilestonedProperty(): Boolean[1]
{
let tree = #{Product{
id,
name,
synonyms(%2023-10-15T00:00:00)
{
synonym
}
}}#;
let query = {|Product.all(%2023-10-15T00:00:00)->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::milestoning::embedded::otherwiseMapping3;
let runtime = meta::external::store::relational::tests::testRuntime();


let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'[{"id":2,"name":"ProductName2","synonyms(2023-10-15T00:00:00+0000)":[{"synonym":"GS-Mod-S1"},{"synonym":"GS-Mod-S3"}]},' +
' {"id":3,"name":"ProductName3","synonyms(2023-10-15T00:00:00+0000)":[]}]"'
,$result);
}

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMultiLevelMilestoning(): Boolean[1]
{
let tree = #{
Order {
id,
product(%2015-10-16) {
id,
name,
type,
classification(%2015-10-16) {
type
}
}
}
}#;
let query = {|Order.all()->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::milestoning::embedded::otherwiseMapping3;
let runtime = meta::external::store::relational::tests::testRuntime();

let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'[{"id":1,"product(2015-10-16)":[]},' +
'{"id":2,"product(2015-10-16)":[{"name":"ProductName2","classification(2015-10-16)":{"type":"STOCK"},"id":2,"type":"STOCK"}]}]',
$result
);
}

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestonedClassAtRootWithQualifierBD(): Boolean[1]
{
let tree = #{
Product {
Expand All @@ -257,27 +356,25 @@ function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::rel
);
}

function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestoning2(): Boolean[1]
function <<test.Test, test.AlloyOnly>> {serverVersion.start='v1_19_0'} meta::relational::graphFetch::tests::embedded::otherwise::testMilestonedClassAtRootWithQualifierNormal(): Boolean[1]
{
let tree = #{
Product {
id,
name,
type,
classification(%2015-10-16) {
type
}
classificationTypeStr
}
}#;
let query = {|Product.all(%2015-10-16)->graphFetch($tree)->serialize($tree)};
let mapping = meta::relational::tests::milestoning::embedded::otherwiseMapping3;
let mapping = meta::relational::tests::milestoning::milestoningmap;
let runtime = meta::external::store::relational::tests::testRuntime();

let result = execute($query, $mapping, $runtime, meta::relational::extension::relationalExtensions()).values;

assertJsonStringsEqual(
'[{"name":"ProductName2","classification(2015-10-16)":{"type":"STOCK"},"id":2,"type":"STOCK"},' +
'{"name":"ProductName3","classification(2015-10-16)":null,"id":3,"type":"OPTION"}]',
'[{"name":"ProductName2","classificationTypeStr()":"STOCK","id":2,"type":"STOCK"},'+
'{"name":"ProductName3","classificationTypeStr()":null,"id":3,"type":"OPTION"}]',
$result
);
}
Expand All @@ -303,15 +400,15 @@ Mapping meta::relational::tests::milestoning::embedded::otherwiseMapping3
classification
(
type: [db]ProductTable.type
) Otherwise([ProductClassification]:[db]@Product_Classification)
) Otherwise([meta_relational_tests_milestoning_ProductClassification]:[db]@Product_Classification)
}

meta::relational::tests::milestoning::ProductSynonym : Relational{
synonym : [db]ProductSynonymTable.synonym,
type : [db]ProductSynonymTable.type
}

meta::relational::tests::milestoning::ProductClassification[ProductClassification] : Relational{
meta::relational::tests::milestoning::ProductClassification[meta_relational_tests_milestoning_ProductClassification] : Relational{
type : [db]ProductClassificationTable.type,
description : [db]ProductClassificationTable.type_description,
product : [db]@Product_Classification
Expand Down

0 comments on commit 7ea5283

Please sign in to comment.