Search in sources :

Example 61 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class FunctionalDependencyExecutor method runAnalysis.

@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
    Boolean runStatus = 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;
            }
            Expression query = dbms().getInstantiatedExpression(indicator);
            if (query == null) {
                // TODO internationalize the string.
                traceError(// $NON-NLS-1$//$NON-NLS-2$
                "Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$
                "query is null");
                runStatus = Boolean.FALSE;
                continue;
            }
            try {
                boolean exeStatus = executeQuery(indicator, connection, query);
                if (!exeStatus) {
                    // TODO internationalize the string.
                    traceError(// $NON-NLS-1$//$NON-NLS-2$
                    "Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + "SQL query: " + // $NON-NLS-1$
                    query.getBody());
                    runStatus = Boolean.FALSE;
                    continue;
                }
            } catch (AnalysisExecutionException e) {
                traceError(e.getMessage());
                runStatus = Boolean.FALSE;
                continue;
            }
            indicator.setComputed(true);
        }
    } finally {
        ReturnCode rc = closeConnection(analysis, connection);
        if (!rc.isOk()) {
            runStatus = Boolean.FALSE;
        }
    }
    return runStatus;
}
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) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)

Example 62 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class FunctionalDependencyExecutor method createInstantiatedSqlExpression.

/**
 * DOC jet Comment method "createInstantiatedSqlExpression".
 *
 * @param sqlGenericExpression
 * @param columnA
 * @param columnB
 * @param dbmsLanguage
 * @param useNulls
 * @return
 */
private Expression createInstantiatedSqlExpression(Expression sqlGenericExpression, TdColumn columnA, TdColumn columnB, DbmsLanguage dbmsLanguage) {
    assert columnA != null;
    assert columnB != null;
    String genericSQL = sqlGenericExpression.getBody();
    // MOD zshen 11005: SQL syntax error for all analysis on Informix databases in Talend Open Profiler
    String table = getTableNameFromColumn(columnA);
    String instantiatedSQL = dbms().fillGenericQueryWithColumnsABAndTable(genericSQL, dbmsLanguage.quote(columnA.getName()), dbmsLanguage.quote(columnB.getName()), table);
    // ~11005
    List<String> whereClauses = new ArrayList<String>();
    String dataFilter = ContextHelper.getDataFilterWithoutContext(cachedAnalysis);
    if (!StringUtils.isEmpty(dataFilter)) {
        whereClauses.add(dataFilter);
    }
    instantiatedSQL = dbms().addWhereToSqlStringStatement(instantiatedSQL, whereClauses);
    Expression instantiatedExpression = CoreFactory.eINSTANCE.createExpression();
    instantiatedExpression.setLanguage(sqlGenericExpression.getLanguage());
    instantiatedExpression.setBody(instantiatedSQL);
    return instantiatedExpression;
}
Also used : Expression(orgomg.cwm.objectmodel.core.Expression) ArrayList(java.util.ArrayList)

Example 63 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class RowMatchingAnalysisExecutor method instantiateQuery.

/**
 * DOC scorreia Comment method "instantiateQuery".
 *
 * @param indicator
 */
private boolean instantiateQuery(Indicator indicator) {
    // (but is not need, hence we keep it commented)
    if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator().equals(indicator.eClass())) {
        RowMatchingIndicator rowMatchingIndicator = (RowMatchingIndicator) indicator;
        EList<TdColumn> columnSetA = rowMatchingIndicator.getColumnSetA();
        EList<TdColumn> columnSetB = rowMatchingIndicator.getColumnSetB();
        if (columnSetA.size() != columnSetB.size()) {
            // $NON-NLS-1$
            traceError("Cannot compare two column sets with different size");
            return Boolean.FALSE;
        // break;
        }
        IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
        Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
        // TODO scorreia create an indicator for each option
        boolean useNulls = false;
        Expression instantiatedSqlExpression = createInstantiatedSqlExpression(sqlGenericExpression, columnSetA, columnSetB, useNulls, indicator);
        indicator.setInstantiatedExpression(instantiatedSqlExpression);
        return true;
    }
    // $NON-NLS-1$
    traceError("Unhandled given indicator: " + AnalysisExecutorHelper.getIndicatorName(indicator));
    return Boolean.FALSE;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) Expression(orgomg.cwm.objectmodel.core.Expression) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 64 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class AnalysisTableTreeViewer method isExpressionNull.

private String isExpressionNull(TreeItem item) {
    String expressContent = null;
    TableIndicatorUnit indicatorUnit = (TableIndicatorUnit) item.getData(INDICATOR_UNIT_KEY);
    TableIndicator tableIndicator = (TableIndicator) item.getData(TABLE_INDICATOR_KEY);
    NamedColumnSet set = tableIndicator.getColumnSet();
    Connection dataprovider = ConnectionHelper.getTdDataProvider(ColumnSetHelper.getParentCatalogOrSchema(set));
    DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
    Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
    if (expression != null) {
        expressContent = expression.getBody();
    }
    return expressContent;
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) Expression(orgomg.cwm.objectmodel.core.Expression) Connection(org.talend.core.model.metadata.builder.connection.Connection) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Example 65 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method viewQueryForSelectedElement.

/**
 * DOC mzhao Comment method "viewQueryForSelectedElement".
 *
 * @param newTree
 */
private void viewQueryForSelectedElement(Tree newTree) {
    TreeItem[] selection = newTree.getSelection();
    for (TreeItem item : selection) {
        ModelElementIndicator meIndicator = (ModelElementIndicator) item.getData(AbstractColumnDropTree.MODELELEMENT_INDICATOR_KEY);
        ConnectionItem connItem = (ConnectionItem) meIndicator.getModelElementRepositoryNode().getObject().getProperty().getItem();
        Connection dataprovider = connItem.getConnection();
        IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
        DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
        Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
        if (expression == null) {
            MessageDialogWithToggle.openWarning(null, DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.Warn"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.NoQueryDefined"));
            return;
        }
        SqlExplorerUtils.getDefault().runInDQViewer(dataprovider, expression.getBody(), meIndicator.getModelElementRepositoryNode().getObject().getProperty().getLabel());
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TreeItem(org.eclipse.swt.widgets.TreeItem) Expression(orgomg.cwm.objectmodel.core.Expression) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

Expression (orgomg.cwm.objectmodel.core.Expression)71 TdExpression (org.talend.cwm.relational.TdExpression)42 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)37 Test (org.junit.Test)25 Domain (org.talend.dataquality.domain.Domain)14 ArrayList (java.util.ArrayList)13 TdColumn (org.talend.cwm.relational.TdColumn)11 Pattern (org.talend.dataquality.domain.pattern.Pattern)10 Catalog (orgomg.cwm.resource.relational.Catalog)10 Indicator (org.talend.dataquality.indicators.Indicator)9 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Analysis (org.talend.dataquality.analysis.Analysis)7 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)6