@finos/legend-extension-dsl-data-quality
Version:
Legend extension for Data Quality
136 lines • 6.05 kB
JavaScript
/**
* Copyright (c) 2026-present, 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.
*/
import { ColSpecArray, matchFunctionName, } from '@finos/legend-graph';
import { DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS, DATA_QUALITY_TERMINAL_ASSERTION_HELPER_FUNCTIONS, DATA_QUALITY_VALIDATION_PURE_FUNCTIONS, SUPPORTED_TYPES, } from '../constants/DataQualityConstants.js';
import { DataQualityValidationAssertionFunction, DataQualityValidationCustomHelperFunction, DataQualityValidationFilterCondition, DataQualityValidationFilterFunction, DataQualityValidationLogicalGroupFunction, DataQualityValidationPropertyGuarantee, } from './DataQualityValidationFunction.js';
import { UnsupportedOperationError } from '@finos/legend-shared';
import { DataQualityFunctionDefaults } from './DataQualityFunctionDefaults.js';
import { DataQualityLambdaParameterParser, } from './DataQualityLambdaParameterParser.js';
export class DataQualityValidationFunctionFactory {
graph;
observerContext;
constructor(graph, observerContext) {
this.graph = graph;
this.observerContext = observerContext;
}
createCustomHelperFunction(name) {
const otherParams = DataQualityFunctionDefaults.getHelperFunctionDefaults(name, this.graph, this.observerContext);
const column = DataQualityLambdaParameterParser.processColSpec({
value: '',
}, this.observerContext);
return new DataQualityValidationCustomHelperFunction(name, {
otherParams,
column,
});
}
createFilterFunction() {
const body = this.createEmptyFilterConditionFunction();
return new DataQualityValidationFilterFunction({
lambda: {
body,
},
});
}
createFilterConditionFunction(name, propertyName) {
const otherParams = DataQualityFunctionDefaults.getPureFunctionDefaults(name, this.graph, this.observerContext);
const property = DataQualityLambdaParameterParser.processPropertyParameter({
property: propertyName ?? '',
parameters: [
{
name: 'row',
_type: SUPPORTED_TYPES.VAR,
},
],
}, this.observerContext);
return new DataQualityValidationFilterCondition(name, {
property,
otherParams,
});
}
createPropertyGuaranteeFunction(name, propertyName) {
const property = DataQualityLambdaParameterParser.processPropertyParameter({
property: propertyName ?? '',
parameters: [
{
name: 'row',
_type: SUPPORTED_TYPES.VAR,
},
],
}, this.observerContext);
return new DataQualityValidationPropertyGuarantee(name, {
property,
});
}
createLogicalFunction(name) {
return new DataQualityValidationLogicalGroupFunction(name, {
left: this.createEmptyFilterConditionFunction(),
right: this.createEmptyFilterConditionFunction(),
});
}
createAssertionFunction(name) {
const columns = DataQualityLambdaParameterParser.processColSpecArray({
value: new ColSpecArray(),
}, this.observerContext);
return new DataQualityValidationAssertionFunction(name, { columns });
}
createEmptyFilterConditionFunction() {
const property = DataQualityLambdaParameterParser.processPropertyParameter({
property: '',
parameters: [
{
name: 'row',
_type: SUPPORTED_TYPES.VAR,
},
],
}, this.observerContext);
return new DataQualityValidationFilterCondition('', {
property,
otherParams: [],
});
}
createFunction(name) {
if (matchFunctionName(name, DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.FILTER)) {
return this.createFilterFunction();
}
if (matchFunctionName(name, Object.values(DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS))) {
return this.createCustomHelperFunction(name);
}
if (matchFunctionName(name, Object.values(DATA_QUALITY_TERMINAL_ASSERTION_HELPER_FUNCTIONS))) {
return this.createAssertionFunction(name);
}
throw new UnsupportedOperationError(`Cannot process function: ${name}`);
}
createFilterChildFunction(name) {
if (matchFunctionName(name, [
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.CONTAINS,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.ENDS_WITH,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.STARTS_WITH,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.EQUAL,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IN,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.GREATER_THAN,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.GREATER_THAN_EQUAL,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.LESS_THAN,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.LESS_THAN_EQUAL,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IS_EMPTY,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IS_NOT_EMPTY,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.MATCHES,
])) {
return this.createFilterConditionFunction(name);
}
throw new UnsupportedOperationError(`Cannot process function: ${name}`);
}
}
//# sourceMappingURL=DataQualityValidationFunctionFactory.js.map