@finos/legend-extension-dsl-data-quality
Version:
Legend extension for Data Quality
179 lines • 10.7 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 { UnsupportedOperationError } from '@finos/legend-shared';
import { DATA_QUALITY_VALIDATION_PURE_FUNCTIONS, DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS, SUPPORTED_TYPES, } from '../constants/DataQualityConstants.js';
import { PRIMITIVE_TYPE, } from '@finos/legend-graph';
import { buildPrimitiveCollectionInstanceValue, buildPrimitiveInstanceValue, } from '@finos/legend-query-builder';
export class DataQualityFunctionDefaults {
static getHelperFunctionDefaults(functionName, graph, observerContext) {
switch (functionName) {
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_EMPTY_COLUMN:
return [];
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_NON_EMPTY_COLUMN:
return [];
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_COLUMN_LONGER_THAN:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
];
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_NEGATIVE_VALUE:
return [];
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_COLUMN_DIFFERS_FROM_PATTERN:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, '', observerContext),
];
case DATA_QUALITY_FILTER_VALIDATION_HELPER_FUNCTIONS.ROWS_WITH_VALUE_OUTSIDE_RANGE:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 1, observerContext),
];
default:
throw new UnsupportedOperationError(`Cannot process function: ${functionName}`);
}
}
static getFilterFunctionDefaults(functionName) {
switch (functionName) {
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.FILTER:
return {
defaultParams: {
column: {
type: SUPPORTED_TYPES.COL_SPEC,
},
otherParams: [],
},
};
default:
throw new UnsupportedOperationError(`Cannot process function: ${functionName}`);
}
}
static getPureFunctionDefaults(functionName, graph, observerContext) {
switch (functionName) {
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.EQUAL:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, '', observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IN:
return [
buildPrimitiveCollectionInstanceValue(graph, PRIMITIVE_TYPE.STRING, [], observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.GREATER_THAN:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.GREATER_THAN_EQUAL:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.LESS_THAN:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.LESS_THAN_EQUAL:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.INTEGER, 0, observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.CONTAINS:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, ' ', observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.STARTS_WITH:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, '', observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.ENDS_WITH:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, '', observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.MATCHES:
return [
buildPrimitiveInstanceValue(graph, PRIMITIVE_TYPE.STRING, '', observerContext),
];
case DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.FILTER:
return [];
default:
throw new UnsupportedOperationError(`Cannot process pure function: ${functionName}`);
}
}
static getFunctionDescriptionTemplate(functionName) {
const allTemplates = {
...DataQualityFunctionDefaults.pureFunctionValidationDescriptionTemplates,
...DataQualityFunctionDefaults.helperFunctionValidationDescriptionTemplates,
};
return allTemplates[functionName] ?? '';
}
static getFunctionNameTemplate(functionName) {
const allTemplates = {
...DataQualityFunctionDefaults.pureFunctionValidationNameTemplates,
...DataQualityFunctionDefaults.helperFunctionValidationNameTemplates,
};
return allTemplates[functionName] ?? '';
}
static pureFunctionValidationNameTemplates = {
[]: '[column]Not[param-1]',
[]: '[column]NotIn[param-1]',
[]: '[column]NotLessThan[param-1]',
[]: '[column]NotBeLessThanOrEqualTo[param-1]',
[]: '[column]NotGreaterThan[param-1]',
[]: '[column]NotGreaterThanOrEqualTo[param-1]',
[]: '[column]NotContain[param-1]',
[]: '[column]NotStartWith[param-1]',
[]: '[column]NotEndWith[param-1]',
[]: '[column]NotMatchRegex[param-1]',
[]: '',
};
static helperFunctionValidationNameTemplates = {
[]: '[column]NotNull',
[]: '[column]IsNull',
[]: '[column]NotLongerThan[param-1]',
[]: '[column]NotNegative',
[]: '[column]ShouldSatisfyPattern',
[]: '[column]Between[param-1]And[param-2]',
};
static helperFunctionValidationDescriptionTemplates = {
[]: 'Expect [column] not to be null',
[]: 'Expect [column] to be null',
[]: 'Expect [column] to be shorter than [param-1]',
[]: 'Expect [column] to be positive',
[]: 'Expect [column] to satisfy the specified pattern',
[]: 'Expect [column] to be between [param-1] and [param-2]',
};
static pureFunctionValidationDescriptionTemplates = {
[]: 'Expect [column] not to equal [param-1]',
[]: 'Expect [column] not be in [param-1]',
[]: 'Expect [column] to be less than [param-1]',
[]: 'Expect [column] to be less than or equal to [param-1]',
[]: 'Expect [column] to be greater than [param-1]',
[]: 'Expect [column] to be greater than or equal to [param-1]',
[]: 'Expect [column] not to contain [param-1]',
[]: 'Expect [column] not to start with [param-1]',
[]: 'Expect [column] not to end with [param-1]',
[]: 'Expect [column] not match [param-1]',
[]: '',
};
static FUNCTIONS_ACCEPTING_OPTIONAL = new Set([
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.EQUAL,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IS_EMPTY,
DATA_QUALITY_VALIDATION_PURE_FUNCTIONS.IS_NOT_EMPTY,
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,
]);
static getIsPureFunctionColumnRequired(functionName) {
return !DataQualityFunctionDefaults.FUNCTIONS_ACCEPTING_OPTIONAL.has(functionName);
}
}
//# sourceMappingURL=DataQualityFunctionDefaults.js.map