Search in sources :

Example 16 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutor method belongToSameSchemata.

/**
 * Method "belongToSameSchemata" fills in the map this{@link #schemata}.
 *
 * @param tdColumn a column
 * @return false when the given column has an owner different from the one registered in the map.
 */
protected boolean belongToSameSchemata(final ModelElement tdColumn) {
    assert tdColumn != null;
    if (schemata.get(tdColumn) != null) {
        return true;
    }
    // get table or view
    ColumnSet owner = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
    if (owner == null) {
        // $NON-NLS-1$
        setError(Messages.getString("ColumnAnalysisExecutor.NotFoundColumn", tdColumn.getName()));
        return false;
    }
    // get catalog or schema
    Package schema = ColumnSetHelper.getParentCatalogOrSchema(owner);
    if (schema == null) {
        // $NON-NLS-1$
        setError(Messages.getString("ColumnAnalysisExecutor.NoSchemaOrCatalogFound", owner.getName(), tdColumn.getName()));
        return false;
    }
    schemata.put(tdColumn, schema);
    return true;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package)

Example 17 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet 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 18 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet 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)

Example 19 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class AddTdRelationalSwitch method casePrimaryKey.

@Override
public Boolean casePrimaryKey(PrimaryKey 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 pkName = object.getName();
    PrimaryKey primaryKey = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createPrimaryKey();
    primaryKey.setName(pkName);
    if (columnSet instanceof Table) {
        primaryKey = TableHelper.addPrimaryKey((TdTable) columnSet, primaryKey);
        if (tdColumn != null) {
            tdColumn.getUniqueKey().add(primaryKey);
        }
    }
    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) PrimaryKey(orgomg.cwm.resource.relational.PrimaryKey) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 20 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class RowMatchingAnalysisExecutor method getTableName.

/**
 * DOC scorreia Comment method "getTableName".
 *
 * @param columnSetA
 * @return
 */
private String getTableName(EList<TdColumn> columnSetA) {
    String tableName = null;
    for (TdColumn column : columnSetA) {
        if (column == null) {
            continue;
        }
        if (column.eIsProxy()) {
            column = (TdColumn) EObjectHelper.resolveObject(column);
        }
        if (belongToSameSchemata(column)) {
            ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(column);
            if (columnSetOwner == null) {
                // $NON-NLS-1$
                log.error(Messages.getString("FunctionalDependencyExecutor.COLUMNSETOWNERISNULL", column.getName()));
                continue;
            } else {
                tableName = dbms().getQueryColumnSetWithPrefix(column);
                // ~11005
                this.catalogOrSchema = getCatalogOrSchemaName(column);
                // all columns should belong to the same table
                break;
            }
        } else {
            log.error(getErrorMessage());
        }
    }
    return quote(tableName);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Aggregations

ColumnSet (orgomg.cwm.resource.relational.ColumnSet)55 TdColumn (org.talend.cwm.relational.TdColumn)35 Package (orgomg.cwm.objectmodel.core.Package)14 ArrayList (java.util.ArrayList)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)11 Connection (org.talend.core.model.metadata.builder.connection.Connection)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 ReloadCompareException (org.talend.cwm.compare.exception.ReloadCompareException)7 TdTable (org.talend.cwm.relational.TdTable)7 Catalog (orgomg.cwm.resource.relational.Catalog)7 Schema (orgomg.cwm.resource.relational.Schema)7 Resource (org.eclipse.emf.ecore.resource.Resource)6 EObject (org.eclipse.emf.ecore.EObject)5 ReturnCode (org.talend.utils.sugars.ReturnCode)5 Indicator (org.talend.dataquality.indicators.Indicator)4 IRepositoryNode (org.talend.repository.model.IRepositoryNode)4 List (java.util.List)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)3