Search in sources :

Example 1 with AnalysisExecutionException

use of org.talend.cwm.exception.AnalysisExecutionException in project tdq-studio-se by Talend.

the class ColumnAnalysisSqlExecutor method getCountLow.

/**
 * DOC scorreia Comment method "getCount".
 *
 * @param cachedAnalysis2
 * @param colName
 * @param quote
 * @param whereExpression
 * @param catalogName
 * @return -1L when sql went ok, but obtained result set is invalid.
 * @throws SQLException
 * @throws AnalysisExecutionException
 */
private Long getCountLow(Analysis analysis, String colName, String table, String catalogName, List<String> whereExpression) throws SQLException, AnalysisExecutionException {
    TypedReturnCode<Connection> trc = this.getConnection(analysis);
    if (!trc.isOk()) {
        throw new AnalysisExecutionException(Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisSqlExecutor.CannotExecuteAnalysis", // $NON-NLS-1$
        analysis.getName(), trc.getMessage()));
    }
    Connection connection = trc.getObject();
    String whereExp = (whereExpression == null || whereExpression.isEmpty()) ? PluginConstant.EMPTY_STRING : // $NON-NLS-1$
    " WHERE " + dbms().buildWhereExpression(whereExpression);
    // + dbms().eos(); //$NON-NLS-1$ //$NON-NLS-2$
    String queryStmt = "SELECT COUNT(" + colName + ") FROM " + table + whereExp;
    List<Object[]> myResultSet = executeQuery(catalogName, connection, queryStmt);
    org.talend.utils.sql.ConnectionUtils.closeConnection(connection);
    if (myResultSet.isEmpty() || myResultSet.size() > 1) {
        // $NON-NLS-1$
        log.error(Messages.getString("ColumnAnalysisSqlExecutor.TOOMANYRESULTOBTAINED") + myResultSet);
        return -1L;
    }
    // $NON-NLS-1$
    return Long.valueOf(String.valueOf(myResultSet.get(0)[0]).split("\\.")[0]);
// ~
}
Also used : AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection)

Example 2 with AnalysisExecutionException

use of org.talend.cwm.exception.AnalysisExecutionException 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)

Example 3 with AnalysisExecutionException

use of org.talend.cwm.exception.AnalysisExecutionException in project tdq-studio-se by Talend.

the class FunctionalDependencyExecutor method executeQuery.

private boolean executeQuery(Indicator indicator, Connection connection, Expression query) throws AnalysisExecutionException {
    try {
        List<Object[]> myResultSet = executeQuery(catalogName, connection, query.getBody());
        indicator.storeSqlResults(myResultSet);
    } catch (SQLException e) {
        log.error(e, e);
        // MOD TDQ-8388 return the exact error message
        throw new AnalysisExecutionException(e.getMessage());
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException)

Example 4 with AnalysisExecutionException

use of org.talend.cwm.exception.AnalysisExecutionException in project tdq-studio-se by Talend.

the class RowMatchingAnalysisExecutor method runAnalysis.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
     * java.lang.String)
     */
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
    boolean isSuccess = Boolean.TRUE;
    TypedReturnCode<java.sql.Connection> trc = this.getConnectionBeforeRun(analysis);
    if (!trc.isOk()) {
        log.error(trc.getMessage());
        setError(trc.getMessage());
        traceError(Messages.getString("FunctionalDependencyExecutor.CANNOTEXECUTEANALYSIS", analysis.getName(), // $NON-NLS-1$
        trc.getMessage()));
        return Boolean.FALSE;
    }
    Connection connection = trc.getObject();
    try {
        // execute the sql statement for each indicator
        EList<Indicator> indicators = analysis.getResults().getIndicators();
        EList<Indicator> deactivatedIndicators = analysis.getParameters().getDeactivatedIndicators();
        for (Indicator indicator : indicators) {
            if (deactivatedIndicators.contains(indicator)) {
                // do not evaluate this indicator
                continue;
            }
            // set the connection's catalog
            if (this.catalogOrSchema != null && needChangeCatalog(connection)) {
                // check whether null argument can be given
                changeCatalog(this.catalogOrSchema, connection);
            }
            Expression query = dbms().getInstantiatedExpression(indicator);
            if (query == null) {
                traceError(// $NON-NLS-1$//$NON-NLS-2$
                "Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$
                "query is null");
                isSuccess = Boolean.FALSE;
                continue;
            }
            try {
                Boolean isExecSuccess = executeQuery(indicator, connection, query);
                indicator.setComputed(true);
                if (!isExecSuccess) {
                    traceError(// $NON-NLS-1$//$NON-NLS-2$
                    "Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + "SQL query: " + // $NON-NLS-1$
                    query.getBody());
                    isSuccess = Boolean.FALSE;
                    continue;
                }
            } catch (AnalysisExecutionException e) {
                traceError(e.getMessage());
                isSuccess = Boolean.FALSE;
                continue;
            }
        }
    } finally {
        ReturnCode rc = closeConnection(analysis, connection);
        if (!rc.isOk()) {
            isSuccess = Boolean.FALSE;
        }
    }
    return isSuccess;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Expression(orgomg.cwm.objectmodel.core.Expression) AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) Connection(java.sql.Connection) Indicator(org.talend.dataquality.indicators.Indicator) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator)

Example 5 with AnalysisExecutionException

use of org.talend.cwm.exception.AnalysisExecutionException in project tdq-studio-se by Talend.

the class ColumnAnalysisSqlExecutor method createSqlStatement.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
     */
@Override
public String createSqlStatement(Analysis analysis) {
    this.cachedAnalysis = analysis;
    AnalysisResult results = analysis.getResults();
    assert results != null;
    try {
        // --- get data filter
        ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
        handler.setAnalysis(analysis);
        String stringDataFilter = handler.getStringDataFilter();
        // --- get all the leaf indicators used for the sql computation
        Collection<Indicator> leafIndicators = IndicatorHelper.getIndicatorLeaves(results);
        // --- create one sql statement for each leaf indicator
        for (Indicator indicator : leafIndicators) {
            if (!this.continueRun()) {
                break;
            }
            if (!createSqlQuery(stringDataFilter, indicator)) {
                log.error(Messages.getString("ColumnAnalysisSqlExecutor.CREATEQUERYERROR", // $NON-NLS-1$
                AnalysisExecutorHelper.getIndicatorName(indicator)));
            // return null;
            }
        }
    } catch (AnalysisExecutionException e) {
        log.error(e, e);
        return null;
    }
    return PluginConstant.EMPTY_STRING;
}
Also used : AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator)

Aggregations

AnalysisExecutionException (org.talend.cwm.exception.AnalysisExecutionException)8 Indicator (org.talend.dataquality.indicators.Indicator)4 Connection (java.sql.Connection)3 ReturnCode (org.talend.utils.sugars.ReturnCode)3 SQLException (java.sql.SQLException)2 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)2 RowMatchingIndicator (org.talend.dataquality.indicators.columnset.RowMatchingIndicator)2 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)2 Expression (orgomg.cwm.objectmodel.core.Expression)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 Analysis (org.talend.dataquality.analysis.Analysis)1 ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)1 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)1 NullCountIndicator (org.talend.dataquality.indicators.NullCountIndicator)1 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)1 ColumnDependencyIndicator (org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)1 WhereRuleIndicator (org.talend.dataquality.indicators.sql.WhereRuleIndicator)1