Search in sources :

Example 6 with RowMatchingIndicator

use of org.talend.dataquality.indicators.columnset.RowMatchingIndicator 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 7 with RowMatchingIndicator

use of org.talend.dataquality.indicators.columnset.RowMatchingIndicator in project tdq-studio-se by Talend.

the class RowMatchingAnalysisExecutor method executeQuery.

/**
 * DOC scorreia Comment method "executeQuery".
 *
 * @param indicator
 * @param connection
 * @param query
 * @return
 * @throws AnalysisExecutionException
 */
private boolean executeQuery(Indicator indicator, Connection connection, Expression query) throws AnalysisExecutionException {
    try {
        List<Object[]> myResultSet = executeQuery(catalogOrSchema, connection, query.getBody());
        String tableName = getAnalyzedTable(indicator);
        // MOD xqliu 2009-06-16 bug 7334
        // set data filter here
        reversion = indiReversionMap != null && indiReversionMap.get(indicator) != null ? indiReversionMap.get(indicator).booleanValue() : false;
        String stringDataFilter = reversion ? ContextHelper.getDataFilterWithoutContext(this.cachedAnalysis, AnalysisHelper.DATA_FILTER_B) : ContextHelper.getDataFilterWithoutContext(this.cachedAnalysis, AnalysisHelper.DATA_FILTER_A);
        List<String> whereClauses = new ArrayList<String>();
        if (stringDataFilter != null && !stringDataFilter.trim().equals(PluginConstant.EMPTY_STRING)) {
            whereClauses.add(stringDataFilter);
        }
        // ~
        // give result to indicator so that it handles the results
        boolean ok = indicator.storeSqlResults(myResultSet);
        // get row count and store it in indicator
        // $NON-NLS-1$
        Long count = getCount(cachedAnalysis, "*", tableName, catalogOrSchema, whereClauses);
        ok = ok && count != null;
        indicator.setCount(count);
        // compute matching count
        if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator().equals(indicator.eClass())) {
            RowMatchingIndicator rowMatchingIndicator = (RowMatchingIndicator) indicator;
            Long notMatchingValueCount = rowMatchingIndicator.getNotMatchingValueCount();
            ok = ok && notMatchingValueCount != null;
            if (ok) {
                rowMatchingIndicator.setMatchingValueCount(count - notMatchingValueCount);
            }
        }
        return ok;
    } catch (SQLException e) {
        log.error(e, e);
        // MOD TDQ-8388 return the exact error message
        throw new AnalysisExecutionException(e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) ArrayList(java.util.ArrayList)

Example 8 with RowMatchingIndicator

use of org.talend.dataquality.indicators.columnset.RowMatchingIndicator in project tdq-studio-se by Talend.

the class RowMatchExplorer method getAllRowsStatement.

/**
 * get All Rows Statement.
 *
 * @return
 */
public String getAllRowsStatement() {
    ColumnSet tablea = (ColumnSet) indicator.getAnalyzedElement();
    String tableA = tablea.getName();
    ColumnSet tableb = ColumnHelper.getColumnOwnerAsColumnSet(((RowMatchingIndicator) indicator).getColumnSetB().get(0));
    String tableB = tableb.getName();
    return getComment(MENU_VIEW_ROWS) + "SELECT * " + dbmsLanguage.from() + getFullyQualifiedTableName(tablea) + // $NON-NLS-1$
    whereDataFilter(tableA.equals(tableB) ? null : tableA, null);
}
Also used : RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 9 with RowMatchingIndicator

use of org.talend.dataquality.indicators.columnset.RowMatchingIndicator in project tdq-studio-se by Talend.

the class RowMatchExplorer method getRowsMatchStatement.

/**
 * get Rows for Matched Statement.
 *
 * @return
 */
public String getRowsMatchStatement() {
    ColumnSet tablea = (ColumnSet) indicator.getAnalyzedElement();
    String tableA = tablea.getName();
    String query = PluginConstant.EMPTY_STRING;
    if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator() == indicator.eClass()) {
        ColumnSet tableb = ColumnHelper.getColumnOwnerAsColumnSet(((RowMatchingIndicator) indicator).getColumnSetB().get(0));
        String tableB = tableb.getName();
        EList<TdColumn> columnSetA = ((RowMatchingIndicator) indicator).getColumnSetA();
        EList<TdColumn> columnSetB = ((RowMatchingIndicator) indicator).getColumnSetB();
        // $NON-NLS-1$
        String clauseA = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tablea);
        // $NON-NLS-1$
        String clauseB = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tableb);
        String where = null;
        // $NON-NLS-1$
        String onClause = " ON ";
        for (int i = 0; i < columnSetA.size(); i++) {
            where = dbmsLanguage.and();
            if (i == 0) {
                where = dbmsLanguage.where();
            } else {
                onClause += where;
            }
            onClause += // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            " (A" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetA.get(i).getName()) + "=" + " B" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetB.get(i).getName()) + // $NON-NLS-1$
            ") ";
        }
        clauseA += (tableA.equals(tableB) ? whereDataFilter(tableA, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_A : AnalysisHelper.DATA_FILTER_B)) : whereDataFilter(tableA, null)) + // $NON-NLS-1$
        ") A";
        clauseB += (tableB.equals(tableA) ? whereDataFilter(tableB, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_B : AnalysisHelper.DATA_FILTER_A)) : whereDataFilter(tableB, null)) + // $NON-NLS-1$
        ") B";
        // $NON-NLS-1$
        query = "SELECT * FROM " + getFullyQualifiedTableName(tablea);
        String clause = PluginConstant.EMPTY_STRING;
        String columnNameByAlias = PluginConstant.EMPTY_STRING;
        for (int i = 0; i < columnSetA.size(); i++) {
            // $NON-NLS-1$
            columnNameByAlias += " A" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetA.get(i).getName());
            if (i != columnSetA.size() - 1) {
                // $NON-NLS-1$
                columnNameByAlias += ",";
            }
        }
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        clause = "(SELECT " + columnNameByAlias + dbmsLanguage.from() + clauseA + " JOIN " + clauseB + onClause + ")";
        // $NON-NLS-1$
        String fullColumnAName = "(";
        for (int j = 0; j < columnSetA.size(); j++) {
            fullColumnAName += getFullyQualifiedTableName(tablea) + PluginConstant.DOT_STRING + dbmsLanguage.quote(columnSetA.get(j).getName());
            if (j != columnSetA.size() - 1) {
                // $NON-NLS-1$
                fullColumnAName += ",";
            } else {
                // $NON-NLS-1$
                fullColumnAName += ")";
            }
        }
        // $NON-NLS-1$
        clause = dbmsLanguage.where() + "(" + fullColumnAName + dbmsLanguage.in() + clause;
        query += clause;
        query += // $NON-NLS-1$
        ") " + (tableA.equals(tableB) ? andDataFilter(tableA, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_A : AnalysisHelper.DATA_FILTER_B)) : andDataFilter(tableA, null));
    }
    return getComment(MENU_VIEW_MATCH_ROWS) + query;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 10 with RowMatchingIndicator

use of org.talend.dataquality.indicators.columnset.RowMatchingIndicator in project tdq-studio-se by Talend.

the class AnalysisColumnCompareTreeViewer method updateModelViewer.

@Override
public void updateModelViewer() {
    if (analysis.getResults().getIndicators().size() != 0) {
        EList<Indicator> indicators = analysis.getResults().getIndicators();
        // ColumnDependencyIndicator and update view
        if (indicators.get(0) instanceof ColumnDependencyIndicator) {
            columnListA.clear();
            columnListB.clear();
            ColumnDependencyIndicator cdi = null;
            for (int i = 0; i < indicators.size(); i++) {
                cdi = (ColumnDependencyIndicator) indicators.get(i);
                columnListA.add(RepositoryNodeHelper.recursiveFind(cdi.getColumnA()));
                columnListB.add(RepositoryNodeHelper.recursiveFind(cdi.getColumnB()));
            }
            tableViewerPosStack.get(0).setInput(columnListA);
            tableViewerPosStack.get(1).setInput(columnListB);
        } else {
            RowMatchingIndicator rowMatchingIndicatorA = (RowMatchingIndicator) indicators.get(0);
            columnListA.clear();
            for (TdColumn tdColumn : rowMatchingIndicatorA.getColumnSetA()) {
                columnListA.add(RepositoryNodeHelper.recursiveFind(tdColumn));
            }
            tableViewerPosStack.get(0).setInput(columnListA);
            columnListB.clear();
            // columnListB.addAll(rowMatchingIndicatorA.getColumnSetB());
            for (TdColumn tdColumn : rowMatchingIndicatorA.getColumnSetB()) {
                columnListB.add(RepositoryNodeHelper.recursiveFind(tdColumn));
            }
            tableViewerPosStack.get(1).setInput(columnListB);
        }
    } else {
        // MOD mzhao bug 12766, 2010-04-22 refresh the viewer.
        columnListA.clear();
        columnListB.clear();
        // MOD qiongli 2010-6-8, bug 13595
        // tableViewerPosStack.get(0).setInput(null);
        // tableViewerPosStack.get(1).setInput(null);
        tableViewerPosStack.get(0).setInput(columnListA);
        tableViewerPosStack.get(1).setInput(columnListB);
    // ~
    }
}
Also used : ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) TdColumn(org.talend.cwm.relational.TdColumn) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)

Aggregations

RowMatchingIndicator (org.talend.dataquality.indicators.columnset.RowMatchingIndicator)10 TdColumn (org.talend.cwm.relational.TdColumn)7 Indicator (org.talend.dataquality.indicators.Indicator)4 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)3 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Table (org.eclipse.swt.widgets.Table)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 Analysis (org.talend.dataquality.analysis.Analysis)2 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 BeforeClass (org.junit.BeforeClass)1 AnalysisExecutionException (org.talend.cwm.exception.AnalysisExecutionException)1 TdTable (org.talend.cwm.relational.TdTable)1 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)1 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)1 ColumnDependencyIndicator (org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)1