Search in sources :

Example 6 with ExecutionInformations

use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.

the class MultiColumnAnalysisExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("tbi");
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("customer");
    tdTable.setNamespace(catalog);
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("date_accnt_opened");
    tdColumn.setContentType(DataminingType.INTERVAL.getName());
    TdColumn tdColumn2 = RelationalFactory.eINSTANCE.createTdColumn();
    tdColumn2.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn2.setName("product_id");
    tdColumn2.setContentType(DataminingType.INTERVAL.getName());
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    // set analysis type is columnset
    analysisPara.setAnalysisType(AnalysisType.COLUMN_SET);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    context.getAnalysedElements().add(tdColumn2);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    simpleStatIndicator = ColumnsetFactory.eINSTANCE.createSimpleStatIndicator();
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody(// $NON-NLS-1$
    "SELECT <%=__COLUMN_NAMES__%> FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%> GROUP BY <%=__GROUP_BY_ALIAS__%>");
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    indicatorDefinition.getSqlGenericExpression().add(expression);
    simpleStatIndicator.setIndicatorDefinition(indicatorDefinition);
    // $NON-NLS-1$
    simpleStatIndicator.getDateFunctions().add("");
    // $NON-NLS-1$
    simpleStatIndicator.getNumericFunctions().add("");
    simpleStatIndicator.setDataminingType(DataminingType.NOMINAL);
    simpleStatIndicator.getAnalyzedColumns().add(tdColumn);
    simpleStatIndicator.getAnalyzedColumns().add(tdColumn2);
    analysisResult.getIndicators().add(simpleStatIndicator);
    analysis.setResults(analysisResult);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Before(org.junit.Before)

Example 7 with ExecutionInformations

use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.

the class SQLPatternExplorerTest method setUp.

/**
 * DOC msjian Comment method "setUp".
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    UnitTestBuildHelper.initProjectStructure();
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
        ITDQItemService tdqService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
        tdqService.createDQStructor();
    }
    sqlPatternExplorer = new SQLPatternExplorer();
    // mock setEntity
    SqlPatternMatchingIndicator indicator = creatSqlPatternMatchingIndicator();
    Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    createAnalysisResult.getIndicators().add(indicator);
    ana.setResults(createAnalysisResult);
    sqlPatternExplorer.setAnalysis(ana);
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(indicator, "name1", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("name1");
    sqlPatternExplorer.setEnitty(chartDataEntity);
    IndicatorDefinition definition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody("SELECT * FROM tbi.customer ");
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    definition.getSqlGenericExpression().add(expression);
    indicator.setIndicatorDefinition(definition);
    indicator.getInstantiatedExpressions().add(expression);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdExpression(org.talend.cwm.relational.TdExpression) Analysis(org.talend.dataquality.analysis.Analysis) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ITDQItemService(org.talend.core.ITDQItemService) Before(org.junit.Before)

Example 8 with ExecutionInformations

use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method setExecutionInfoInAnalysisResult.

/**
 * set the execution info of analysis.
 *
 * @param analysis - which need to update the execution number
 * @param isRunAnaResultok - the running result of the analysis is ok or not
 * @param errorMessage - the error message
 */
public static void setExecutionInfoInAnalysisResult(Analysis analysis, boolean isRunAnaResultok, String errorMessage) {
    final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
    resultMetadata.setLastRunOk(isRunAnaResultok);
    resultMetadata.setMessage(errorMessage);
    resultMetadata.setExecutionNumber(resultMetadata.getExecutionNumber() + 1);
    if (isRunAnaResultok) {
        resultMetadata.setLastExecutionNumberOk(resultMetadata.getLastExecutionNumberOk() + 1);
    }
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations)

Example 9 with ExecutionInformations

use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method setExecutionDateInAnalysisResult.

public static long setExecutionDateInAnalysisResult(Analysis analysis) {
    final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
    final long startime = System.currentTimeMillis();
    resultMetadata.setExecutionDate(new Date(startime));
    return startime;
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) Date(java.util.Date)

Example 10 with ExecutionInformations

use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.

the class ReportExecutor method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.IReportExecutor#execute(org.talend.dataquality.reports.TdReport)
     */
public ReturnCode execute(TdReport report, IProgressMonitor monitor) throws AnalysisExecutionException {
    atLeastOneFailure = false;
    long startTime = System.currentTimeMillis();
    if (report.eIsProxy()) {
        report = (TdReport) EObjectHelper.resolveObject(report);
    }
    EList<AnalysisMap> analysisMaps = report.getAnalysisMap();
    StringBuilder strBuilder = new StringBuilder();
    // loop on analysis maps is faster than loop on analyses
    for (AnalysisMap analysisMap : analysisMaps) {
        Analysis analysis = analysisMap.getAnalysis();
        if (analysisMap.isMustRefresh()) {
            if (analysis == null) {
                return new ReturnCode(Messages.getString("ReportExecutor.CannotEvaluateNullAnalysis", report.getName()), // $NON-NLS-1$
                false);
            }
            ReturnCode executeRc = AnalysisExecutorSelector.executeAnalysis(analysis, monitor);
            if (executeRc.getMessage() != null && !StringUtils.EMPTY.equals(executeRc.getMessage().trim())) {
                throw new AnalysisExecutionException(Messages.getString("ReportExecutor.failRunAnalysis", analysis.getName(), executeRc.getMessage()));
            }
            // ADD msjian TDQ-5952: we should close connections always
            TdqAnalysisConnectionPool.closeConnectionPool(analysis);
            // TDQ-5952~
            if (!executeRc.isOk()) {
                log.error("Failed to execute analysis " + analysis.getName() + ". Reason: " + executeRc.getMessage());
                atLeastOneFailure = true;
            }
            if (log.isInfoEnabled()) {
                strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " refreshed. State: " + executeRc.isOk() + "\n");
            }
        } else {
            // skipped analysis
            if (log.isInfoEnabled()) {
                strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " skipped.\n");
            }
        }
    }
    // log execution
    if (log.isInfoEnabled()) {
        if (strBuilder.length() == 0) {
            log.info("Generating reports for \"" + report.getName() + "\" without refreshing any analysis.");
        } else {
            log.info(strBuilder.toString());
        }
    }
    long endTime = System.currentTimeMillis();
    // fill in the execution informations
    ExecutionInformations execInformations = ReportHelper.getExecutionInformations(report);
    execInformations.setExecutionDate(new Date(startTime));
    int duration = (int) (endTime - startTime);
    execInformations.setExecutionDuration(duration);
    execInformations.setExecutionNumber(execInformations.getExecutionNumber() + 1);
    if (atLeastOneFailure) {
        execInformations.setLastRunOk(false);
        // $NON-NLS-1$
        String err = Messages.getString("ReportExecutor.AnalysisExecutionFailed", report.getName());
        execInformations.setMessage(err);
        return new ReturnCode(err, false);
    }
    // else
    execInformations.setLastRunOk(true);
    execInformations.setLastExecutionNumberOk(execInformations.getExecutionNumber());
    execInformations.setMessage(null);
    return new ReturnCode();
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) Date(java.util.Date)

Aggregations

ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)23 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)13 Analysis (org.talend.dataquality.analysis.Analysis)11 Test (org.junit.Test)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 Date (java.util.Date)5 TdColumn (org.talend.cwm.relational.TdColumn)5 TdTable (org.talend.cwm.relational.TdTable)5 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)5 TdExpression (org.talend.cwm.relational.TdExpression)4 Before (org.junit.Before)3 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)3 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)3 ReturnCode (org.talend.utils.sugars.ReturnCode)3 Package (orgomg.cwm.objectmodel.core.Package)3 SQLException (java.sql.SQLException)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)2