From c03e69aaa8d54b26647dbb8ff2855996097ac4ee Mon Sep 17 00:00:00 2001 From: Vijay Garg Date: Fri, 5 Jul 2024 22:39:29 +0530 Subject: [PATCH] Add resolver for DataQualityValidation element (#2946) * Add resolver for DataQualityValidation element --- .../model/context/PackageableElementType.java | 3 +- .../pom.xml | 4 ++ .../DataQualityCompilerExtension.java | 8 +--- .../toPureGraph/HelperDataQualityBuilder.java | 45 +++++++++++++++++++ .../generation/dataquality.pure | 2 +- 5 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperDataQualityBuilder.java diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/context/PackageableElementType.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/context/PackageableElementType.java index bdf9a0ba4fe..3be6d626f0f 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/context/PackageableElementType.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/context/PackageableElementType.java @@ -34,5 +34,6 @@ public enum PackageableElementType DIAGRAM, FILE_GENERATION, DATA, - QUERYPOSTPROCESSOR + QUERYPOSTPROCESSOR, + DATA_QUALITY_VALIDATION } diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/pom.xml b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/pom.xml index bbde906f93b..e8fad88c3fc 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/pom.xml +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/pom.xml @@ -66,6 +66,10 @@ runtime + + org.finos.legend.engine + legend-engine-protocol + org.finos.legend.engine legend-engine-protocol-pure diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/DataQualityCompilerExtension.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/DataQualityCompilerExtension.java index e7f298ddfeb..935c59eca97 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/DataQualityCompilerExtension.java +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/DataQualityCompilerExtension.java @@ -71,7 +71,7 @@ public MutableList group() return org.eclipse.collections.impl.factory.Lists.mutable.with("PackageableElement", "DataQualityValidation"); } - static final ConcurrentHashMap dataQualityIndex = new ConcurrentHashMap<>(); + static final ConcurrentHashMap> dataQualityIndex = new ConcurrentHashMap<>(); @Override public CompilerExtension build() @@ -106,11 +106,7 @@ public Iterable> getExtraProcessors() }, (dataquality, compileContext) -> { - - }, - (dataquality, compileContext) -> - { - Root_meta_external_dataquality_DataQuality metamodel = dataQualityIndex.get(compileContext.pureModel.buildPackageString(dataquality._package, dataquality.name)); + Root_meta_external_dataquality_DataQuality metamodel = dataQualityIndex.get(compileContext.pureModel.buildPackageString(dataquality._package, dataquality.name)); metamodel._context(buildDataQualityExecutionContext(dataquality, compileContext)) ._filter(getFilterLambda(dataquality, compileContext)) ._validationTree(buildRootGraphFetchTree(dataquality.dataQualityRootGraphFetchTree, compileContext, compileContext.pureModel.getClass(dataquality.dataQualityRootGraphFetchTree._class), null, new ProcessingContext("DataQuality"))); diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperDataQualityBuilder.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperDataQualityBuilder.java new file mode 100644 index 00000000000..409baba01f5 --- /dev/null +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperDataQualityBuilder.java @@ -0,0 +1,45 @@ +// Copyright 2020 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. + +package org.finos.legend.engine.language.pure.compiler.toPureGraph; + +import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; +import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; +import org.finos.legend.engine.shared.core.operational.Assert; +import org.finos.legend.pure.generated.Root_meta_external_dataquality_DataQuality; + +import java.util.Objects; + +public class HelperDataQualityBuilder +{ + private static DataQualityCompilerExtension getDataQualityCompilerExtension(CompileContext context) + { + return Objects.requireNonNull(ListIterate.selectInstancesOf(context.getCompilerExtensions().getExtensions(), DataQualityCompilerExtension.class).getAny(), "DataQuality extension is not in scope"); + } + + public static Root_meta_external_dataquality_DataQuality getDataQuality(String fullPath, SourceInformation sourceInformation, CompileContext context) + { + Root_meta_external_dataquality_DataQuality dataQuality = DataQualityCompilerExtension.dataQualityIndex.get(fullPath); + Assert.assertTrue(dataQuality != null, () -> "Can't find dataquality '" + fullPath + "'", sourceInformation, EngineErrorType.COMPILATION); + return dataQuality; + } + + public static Root_meta_external_dataquality_DataQuality resolveDataQualityValidation(String fullPath, SourceInformation sourceInformation, CompileContext context) + { + return context.resolve(fullPath, sourceInformation, path -> getDataQuality(path, sourceInformation, context)); + } + +} + 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 7af27d2240c..b4de9253fa1 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 @@ -21,7 +21,7 @@ function meta::external::dataquality::executeDataQualityValidation(dataquality:m let enrichedTree = $dataquality.validationTree->ensureFunctionRequirementsForDataQuality($dataquality.validationTree.constraints, $dataquality.validationTree.class, [], true)->cast(@RootGraphFetchTree); // 2. build query - let getAll = $dataquality.validationTree.class->createGetAll(); + let getAll = $dataquality.validationTree.class->createGetAllParameterized(); let getExpr = if ($dataquality.filter->isNotEmpty(), | $dataquality.validationTree.class->generateFilterQuery($getAll, $dataquality.filter->toOne());, | $getAll);