Search in sources :

Example 61 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutor method checkAnalyzedElements.

/**
 * DOC scorreia Comment method "checkAnalyzedElements".
 *
 * @param analysis
 * @param context
 */
protected boolean checkAnalyzedElements(final Analysis analysis, AnalysisContext context) {
    ModelElementAnalysisHandler analysisHandler = new ModelElementAnalysisHandler();
    analysisHandler.setAnalysis(analysis);
    for (ModelElement node : context.getAnalysedElements()) {
        TdColumn column = SwitchHelpers.COLUMN_SWITCH.doSwitch(node);
        // --- Check that each analyzed element has at least one indicator
        if (analysisHandler.getIndicators(column).size() == 0) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.EachColumnHaveOneIndicator"));
            return false;
        }
        // --- get the data provider
        Connection dp = ConnectionHelper.getTdDataProvider(column);
        if (!isAccessWith(dp)) {
            setError(// $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "ColumnAnalysisExecutor.AllColumnsBelongSameConnection", column.getName(), dataprovider.getName()));
            return false;
        }
    }
    return true;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) Connection(org.talend.core.model.metadata.builder.connection.Connection)

Example 62 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutor method evaluate.

@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
    IndicatorEvaluator eval = CreateIndicatorEvaluator(analysis);
    // MOD xqliu 2009-02-09 bug 6237
    eval.setMonitor(getMonitor());
    // set it into the evaluator
    eval.setConnection(connection);
    // use pooled connection
    eval.setPooledConnection(POOLED_CONNECTION);
    // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    RowCountIndicatorsAdapter.getInstance().clear();
    for (Indicator indicator : indicators) {
        assert indicator != null;
        TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(indicator.getAnalyzedElement());
        if (tdColumn == null) {
            continue;
        }
        // --- get the schema owner
        if (!belongToSameSchemata(tdColumn)) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenColumn", tdColumn.getName()));
            return new ReturnCode(getErrorMessage(), Boolean.FALSE);
        }
        String columnName = ColumnHelper.getFullName(tdColumn);
        eval.storeIndicator(columnName, indicator);
    }
    // when to close connection
    boolean closeAtTheEnd = true;
    Package catalog = schemata.values().iterator().next();
    if (!eval.selectCatalog(catalog.getName())) {
        // $NON-NLS-1$
        log.warn(Messages.getString("ColumnAnalysisExecutor.FAILEDTOSELECTCATALOG", catalog.getName()));
    }
    return eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ReturnCode(org.talend.utils.sugars.ReturnCode) IndicatorEvaluator(org.talend.dq.indicators.IndicatorEvaluator) Package(orgomg.cwm.objectmodel.core.Package) Indicator(org.talend.dataquality.indicators.Indicator)

Example 63 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class ColumnAnalysisSqlExecutor method duplicateForCrossJoin.

/**
 * Method "duplicateForCrossJoin". For some SQL queries, auto-joins are used in subqueries. This means that the
 * table has two differents aliases and the columns must be prefixed with the alias of the table. Each where clause
 * must be duplicated. For example, the clause "AGE > 10" must be duplicated to give "a.AGE > 10" and "b.AGE" when
 * table aliases are "a" and "b".
 *
 * @param completedSqlString the SQL query
 *
 * @param whereExpression some where clauses
 * @param tdColumn the analyzed column
 * @return a list of new where clauses (or the one given as argument)
 */
private List<String> duplicateForCrossJoin(String completedSqlString, List<String> whereExpression, TdColumn tdColumn) {
    if (whereExpression.isEmpty()) {
        return whereExpression;
    }
    String quotedColName = getQuotedColumnName(tdColumn);
    String[] tableAliases = getTableTableAliasA(completedSqlString, quotedColName);
    if (tableAliases == null) {
        return whereExpression;
    }
    List<String> duplicatedWhereExpressions = new ArrayList<String>();
    // get the table
    ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
    List<TdColumn> columns = ColumnHelper.getColumns(columnSetOwner.getFeature());
    for (String where : whereExpression) {
        // we expect only 2 table aliases, hence two distinct where clauses.
        String whereA = where;
        String whereB = where;
        for (TdColumn col : columns) {
            String colNameToReplace = where.contains(quotedColName) ? quotedColName : col.getName();
            if (where.contains(colNameToReplace)) {
                whereA = whereA.replace(colNameToReplace, tableAliases[0] + PluginConstant.DOT_STRING + colNameToReplace);
                whereB = whereB.replace(colNameToReplace, tableAliases[1] + PluginConstant.DOT_STRING + colNameToReplace);
            }
        }
        duplicatedWhereExpressions.add(whereA);
        duplicatedWhereExpressions.add(whereB);
    }
    return duplicatedWhereExpressions;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 64 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class ColumnSetAnalysisHandler method addIndicator.

/**
 * The resources that are connected to this analysis and that are potentially modified.
 */
// private Collection<Resource> modifiedResources = new HashSet<Resource>();
/**
 * Method "addColumnToAnalyze".
 *
 * @param column
 * @return
 */
public boolean addIndicator(List<ModelElement> columns, Indicator indicator) {
    for (ModelElement tdColumn : columns) {
        if (!analysis.getContext().getAnalysedElements().contains(tdColumn)) {
            analysis.getContext().getAnalysedElements().add(tdColumn);
        }
    }
    // store first level of indicators in result.
    analysis.getResults().getIndicators().add(indicator);
    initializeIndicator(indicator);
    DataManager connection = analysis.getContext().getConnection();
    if (connection == null) {
        // try to get one
        for (ModelElement element : columns) {
            TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(element);
            // $NON-NLS-1$
            log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
            connection = ConnectionHelper.getTdDataProvider(tdColumn);
            if (connection != null) {
                analysis.getContext().setConnection(connection);
                break;
            }
        }
    }
    TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    return rc.isOk();
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 65 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class AddTdRelationalSwitch method caseForeignKey.

@Override
public Boolean caseForeignKey(ForeignKey object) {
    ColumnSet columnSet = null;
    TdColumn tdColumn = null;
    if (leftElement instanceof TdColumn) {
        tdColumn = (TdColumn) leftElement;
        columnSet = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
    }
    if (columnSet == null) {
        return Boolean.FALSE;
    }
    String fkName = object.getName();
    ForeignKey foreignKey = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createForeignKey();
    foreignKey.setName(fkName);
    if (columnSet instanceof Table) {
        foreignKey = TableHelper.addForeignKey((TdTable) columnSet, foreignKey);
        if (tdColumn != null) {
            tdColumn.getKeyRelationship().add(foreignKey);
        }
    }
    return Boolean.TRUE;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) Table(orgomg.cwm.resource.relational.Table) TdTable(org.talend.cwm.relational.TdTable) TdTable(org.talend.cwm.relational.TdTable) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) ForeignKey(orgomg.cwm.resource.relational.ForeignKey)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)182 ArrayList (java.util.ArrayList)49 TdTable (org.talend.cwm.relational.TdTable)49 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)28 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Catalog (orgomg.cwm.resource.relational.Catalog)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13