From cb657771a9f2dc9414006ea265830c458b6267dc Mon Sep 17 00:00:00 2001 From: Vijay Garg Date: Tue, 13 Aug 2024 13:57:44 +0530 Subject: [PATCH] handle no constraints in a node in metadata gen (#2998) --- .../dataquality_test.pure | 18 ++++++++++++++++++ .../generation/dataquality.pure | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure-test/src/main/resources/core_dataquality_test/dataquality_test.pure b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure-test/src/main/resources/core_dataquality_test/dataquality_test.pure index 598ec2518db..3f00dcdf09a 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure-test/src/main/resources/core_dataquality_test/dataquality_test.pure +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure-test/src/main/resources/core_dataquality_test/dataquality_test.pure @@ -48,6 +48,24 @@ function <> meta::external::dataquality::tests::testLambdaGeneration_ assert($dqLambda->isNotEmpty()); } +function <> 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( + 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(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()); +} + diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure/src/main/resources/core_dataquality/generation/dataquality.pure b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure/src/main/resources/core_dataquality/generation/dataquality.pure index 20b64bc7e3d..15555f4170a 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure/src/main/resources/core_dataquality/generation/dataquality.pure +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-pure/src/main/resources/core_dataquality/generation/dataquality.pure @@ -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[1] | $dr->rootNodeToDqRule($processOnlyConstraints), @@ -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 <> meta::external::dataquality::rootNodeToDqRule(node:RootGraphFetchTree[1], processOnlyConstraints: Boolean[1]):DataQualityRule[*] @@ -456,11 +456,11 @@ function <> meta::external::dataquality::rootNodeToDqRule(node:R ); } -function <> meta::external::dataquality::propertyNodeToDqRule(node:PropertyGraphFetchTree[1], processOnlyConstraints: Boolean[1], path:String[1]):DataQualityRule[*] +function <> 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('::')) ); }