Skip to content

Commit

Permalink
handle no constraints in a node in metadata gen (#2998)
Browse files Browse the repository at this point in the history
  • Loading branch information
keenkeystrokes authored Aug 13, 2024
1 parent 57f8203 commit cb65777
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ function <<test.Test>> meta::external::dataquality::tests::testLambdaGeneration_
assert($dqLambda->isNotEmpty());
}

function <<test.Test>> meta::external::dataquality::tests::testMetadataGeneration():Boolean[1]
{ let dqRootConstraints = meta::external::dataquality::tests::Person->getAllTypeGeneralisations()->filter(x| $x->instanceOf(ElementWithConstraints))->cast(@ElementWithConstraints).constraints->filter(x| $x.name == 'addressIDGreaterThan2' || $x.name == 'nameMustNotBeBlank');

let validationTree = ^DataQualityRootGraphFetchTree<Person>(
class=meta::external::dataquality::tests::Person,
constraints=$dqRootConstraints,
subTrees=meta::external::dataquality::tests::Person->hierarchicalProperties()->filter(p | $p->isPrimitiveValueProperty()->not())->filter(p| $p.name=='addresses')->map(p | ^DataQualityPropertyGraphFetchTree(property=$p,
subTrees=meta::external::dataquality::tests::Address->hierarchicalProperties()->filter(p | $p->isPrimitiveValueProperty())->filter(p| $p.name=='addressId')->map(p | ^DataQualityPropertyGraphFetchTree(property=$p))))
);
let filter = p:Person[1]| $p.name=='John';
let dataquality = ^DataQuality<Person>(validationTree=$validationTree,
context=^meta::external::dataquality::MappingAndRuntimeDataQualityExecutionContext(runtime=^meta::core::runtime::EngineRuntime(connectionStores = testDatabaseConnection(meta::relational::tests::db, [])), mapping=meta::external::dataquality::tests::dqValidationPersonMapping),
filter=$filter);

let dqMetadata = meta::external::dataquality::generateDQMetaDataForDQValidation($dataquality);
assert($dqMetadata->isNotEmpty());
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function meta::external::dataquality::generateDQMetaDataForDQValidation(dataqual
$dqRules;
}

function meta::external::dataquality::nodeToDqRule(node:GraphFetchTree[1], processOnlyConstraints:Boolean[1], path:String[1]):DataQualityRule[*]
function meta::external::dataquality::nodeToDqRule(node:GraphFetchTree[1], processOnlyConstraints:Boolean[1], path:String[*]):DataQualityRule[*]
{
let dqRules = $node->match([
dr: DataQualityRootGraphFetchTree<Any>[1] | $dr->rootNodeToDqRule($processOnlyConstraints),
Expand All @@ -445,7 +445,7 @@ function meta::external::dataquality::nodeToDqRule(node:GraphFetchTree[1], proce
p : PropertyGraphFetchTree[1] | $p->propertyNodeToDqRule($processOnlyConstraints, $path)
]);

$dqRules->concatenate($node.subTrees->map(st|$st->nodeToDqRule($processOnlyConstraints, $dqRules->at(0).propertyPath)));
$dqRules->concatenate($node.subTrees->map(st|$st->nodeToDqRule($processOnlyConstraints, if ($dqRules->isEmpty(), | [], | $dqRules->at(0).propertyPath))));
}

function <<access.private>> meta::external::dataquality::rootNodeToDqRule(node:RootGraphFetchTree<Any>[1], processOnlyConstraints: Boolean[1]):DataQualityRule[*]
Expand All @@ -456,11 +456,11 @@ function <<access.private>> meta::external::dataquality::rootNodeToDqRule(node:R
);
}

function <<access.private>> meta::external::dataquality::propertyNodeToDqRule(node:PropertyGraphFetchTree[1], processOnlyConstraints: Boolean[1], path:String[1]):DataQualityRule[*]
function <<access.private>> meta::external::dataquality::propertyNodeToDqRule(node:PropertyGraphFetchTree[1], processOnlyConstraints: Boolean[1], path:String[*]):DataQualityRule[*]
{
if ( $processOnlyConstraints,
| $node->cast(@DataQualityPropertyGraphFetchTree).constraints->map(c|$c->constraintToDqRule([$path, $node.property.name->toOne()]->joinStrings('::'))),
| ^DataQualityRule(constraintName=$node.property.name->toOne(), constraintGrammar=$node.property.multiplicity->printMultiplicity(), constraintType='Alloy_Structural_Validation', propertyPath=[$path, $node.property.name->toOne()]->joinStrings('::'))
| $node->cast(@DataQualityPropertyGraphFetchTree).constraints->map(c|$c->constraintToDqRule($path->concatenate($node.property.name->toOne())->joinStrings('::'))),
| ^DataQualityRule(constraintName=$node.property.name->toOne(), constraintGrammar=$node.property.multiplicity->printMultiplicity(), constraintType='Alloy_Structural_Validation', propertyPath=$path->concatenate($node.property.name->toOne())->joinStrings('::'))
);
}

Expand Down

0 comments on commit cb65777

Please sign in to comment.