UNPKG

@finos/legend-extension-dsl-data-quality

Version:
158 lines 6.85 kB
/** * Copyright (c) 2020-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 { ExecutionPlanState, QUERY_BUILDER_EVENT, QueryBuilderTelemetryHelper, } from '@finos/legend-query-builder'; import { action, flow, makeObservable, observable } from 'mobx'; import { ActionState, assertErrorThrown, LogEvent, StopWatch, } from '@finos/legend-shared'; import { GRAPH_MANAGER_EVENT, } from '@finos/legend-graph'; import { getDataQualityPureGraphManagerExtension } from '../../graph-manager/protocol/pure/DSL_DataQuality_PureGraphManagerExtension.js'; export const DEFAULT_LIMIT = 1000; export class DataQualityResultState { dataQualityState; executionPlanState; previewLimit = DEFAULT_LIMIT; pressedRunQuery = ActionState.create(); isRunningQuery = false; isGeneratingPlan = false; executionResult; executionDuration; latestRunHashCode; queryRunPromise = undefined; isQueryUsageViewerOpened = false; constructor(dataQualityState) { makeObservable(this, { executionResult: observable, previewLimit: observable, executionDuration: observable, latestRunHashCode: observable, queryRunPromise: observable, isGeneratingPlan: observable, isRunningQuery: observable, setIsRunningQuery: action, setExecutionResult: action, setExecutionDuration: action, setPreviewLimit: action, setQueryRunPromise: action, runQuery: flow, cancelQuery: flow, generatePlan: flow, }); this.dataQualityState = dataQualityState; this.executionPlanState = new ExecutionPlanState(this.dataQualityState.applicationStore, this.dataQualityState.graphManagerState); } setIsRunningQuery(val) { this.isRunningQuery = val; } setExecutionResult(val) { this.executionResult = val; } setExecutionDuration(val) { this.executionDuration = val; } setPreviewLimit(val) { this.previewLimit = Math.max(1, val); } setQueryRunPromise(promise) { this.queryRunPromise = promise; } get checkForStaleResults() { if (this.latestRunHashCode !== this.dataQualityState.hashCode) { return true; } return false; } *runQuery() { let promise; try { this.setIsRunningQuery(true); const currentHashCode = this.dataQualityState.hashCode; const packagePath = this.dataQualityState.constraintsConfigurationElement.path; const model = this.dataQualityState.graphManagerState.graph; const stopWatch = new StopWatch(); promise = getDataQualityPureGraphManagerExtension(this.dataQualityState.graphManagerState.graphManager).execute(model, packagePath, { lambdaParameterValues: this.dataQualityState.lambdaParameterValues, previewLimit: this.previewLimit, }); this.setQueryRunPromise(promise); const result = (yield promise); if (this.queryRunPromise === promise) { this.setExecutionResult(result); this.latestRunHashCode = currentHashCode; this.setExecutionDuration(stopWatch.elapsed); } } catch (error) { if (this.queryRunPromise === promise) { assertErrorThrown(error); this.setExecutionResult(undefined); this.dataQualityState.applicationStore.logService.error(LogEvent.create(GRAPH_MANAGER_EVENT.EXECUTION_FAILURE), error); this.dataQualityState.applicationStore.notificationService.notifyError(error); } } finally { this.setIsRunningQuery(false); this.pressedRunQuery.complete(); } } *cancelQuery() { this.pressedRunQuery.complete(); this.setIsRunningQuery(false); this.setQueryRunPromise(undefined); try { yield this.dataQualityState.graphManagerState.graphManager.cancelUserExecutions(true); } catch (error) { // Don't notify users about success or failure this.dataQualityState.applicationStore.logService.error(LogEvent.create(GRAPH_MANAGER_EVENT.EXECUTION_FAILURE), error); } } *generatePlan(debug) { const packagePath = this.dataQualityState.constraintsConfigurationElement.path; const model = this.dataQualityState.graphManagerState.graph; try { this.isGeneratingPlan = true; let rawPlan; const stopWatch = new StopWatch(); if (debug) { const debugResult = (yield getDataQualityPureGraphManagerExtension(this.dataQualityState.graphManagerState.graphManager).debugExecutionPlanGeneration(model, packagePath, {})); rawPlan = debugResult.plan; this.executionPlanState.setDebugText(debugResult.debug); } else { QueryBuilderTelemetryHelper.logEvent_ExecutionPlanGenerationLaunched(this.dataQualityState.applicationStore.telemetryService); rawPlan = (yield getDataQualityPureGraphManagerExtension(this.dataQualityState.graphManagerState.graphManager).generatePlan(model, packagePath, {})); } stopWatch.record(); try { this.executionPlanState.setRawPlan(rawPlan); const plan = this.dataQualityState.graphManagerState.graphManager.buildExecutionPlan(rawPlan, this.dataQualityState.graphManagerState.graph); this.executionPlanState.initialize(plan); } catch { //do nothing } stopWatch.record(QUERY_BUILDER_EVENT.BUILD_EXECUTION_PLAN__SUCCESS); } catch (error) { assertErrorThrown(error); this.dataQualityState.applicationStore.logService.error(LogEvent.create(GRAPH_MANAGER_EVENT.EXECUTION_FAILURE), error); this.dataQualityState.applicationStore.notificationService.notifyError(error); } finally { this.isGeneratingPlan = false; } } } //# sourceMappingURL=DataQualityResultState.js.map