Search in sources :

Example 66 with TdColumn

use of org.talend.cwm.relational.TdColumn 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 67 with TdColumn

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

the class UpdateTdRelationalSwitch method caseTdColumn.

@Override
public Boolean caseTdColumn(TdColumn object) {
    if (recentElement instanceof TdColumn) {
        TdColumn c = (TdColumn) recentElement;
        object.setName(c.getName());
        object.setLength(c.getLength());
        // MOD klliu update the c.getJavaType()
        object.getSqlDataType().setJavaDataType(c.getSqlDataType().getJavaDataType());
        // ADD msjian TDQ-8546: fix the oracle nullable wrong after reload column list
        object.setNullable(c.isNullable());
        return true;
    }
    return false;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn)

Example 68 with TdColumn

use of org.talend.cwm.relational.TdColumn 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)

Example 69 with TdColumn

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

the class MultiColumnAnalysisExecutor method instantiateQuery.

/**
 * DOC scorreia Comment method "instantiateQuery".
 *
 * @param indicator
 */
private void instantiateQuery(Indicator indicator) {
    if (ColumnsetPackage.eINSTANCE.getColumnSetMultiValueIndicator().isSuperTypeOf(indicator.eClass())) {
        ColumnSetMultiValueIndicator colSetMultValIndicator = (ColumnSetMultiValueIndicator) indicator;
        final EList<ModelElement> analyzedColumns = colSetMultValIndicator.getAnalyzedColumns();
        final EList<String> numericFunctions = initializeNumericFunctions(colSetMultValIndicator);
        final EList<String> dateFunctions = initializeDateFunctions(colSetMultValIndicator);
        // ADD msjian 2011-5-30 17479: Excel Odbc connection can not run well on the correlation analysis
        // note: this feature is not supported now, if support, delete this
        // $NON-NLS-1$
        final String caseStr = "SUM(CASE WHEN {0} IS NULL THEN 1 ELSE 0 END)";
        if (// $NON-NLS-1$
        "EXCEL".equals(dbms().getDbmsName()) && (dateFunctions.contains(caseStr) || numericFunctions.contains(caseStr))) {
            // $NON-NLS-1$
            setError(Messages.getString("MultiColumnAnalysisExecutor.errMessage"));
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString("MultiColumnAnalysisExecutor.errTitle"), // $NON-NLS-1$
                    getErrorMessage());
                    return;
                }
            });
        }
        // ~
        // get indicator definition
        final Expression sqlGenericExpression = dbms().getSqlExpression(indicator.getIndicatorDefinition());
        // separate nominal from numeric columns
        List<String> nominalColumns = new ArrayList<String>();
        for (ModelElement column : colSetMultValIndicator.getNominalColumns()) {
            nominalColumns.add(getQuotedColumnName(column));
        }
        List<String> computedColumns = new ArrayList<String>();
        for (ModelElement column : colSetMultValIndicator.getNumericColumns()) {
            // call functions for each column
            for (String f : numericFunctions) {
                computedColumns.add(replaceVariablesLow(f, getQuotedColumnName(column)));
            }
        }
        for (ModelElement column : colSetMultValIndicator.getDateColumns()) {
            // call functions for each column
            for (String f : dateFunctions) {
                computedColumns.add(replaceVariablesLow(f, getQuotedColumnName(column)));
            }
        }
        // add count(*)
        computedColumns.add(colSetMultValIndicator.getCountAll());
        // MOD msjian TDQ-7254: fix the columnset analysis run get error. the columnset analysis don't need to
        // consider the datamining type.
        List<String> columns = new ArrayList<String>();
        // if the analysis type is columnset, use analyzed columns
        if (AnalysisType.COLUMN_SET == cachedAnalysis.getParameters().getAnalysisType()) {
            for (ModelElement column : analyzedColumns) {
                columns.add(getQuotedColumnName(column));
            }
        } else {
            columns = nominalColumns;
        }
        // TDQ-7254~
        String selectItems = createSelect(columns, computedColumns);
        String grpByClause = createGroupBy(columns);
        // all columns must belong to the same table
        TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analyzedColumns.get(0));
        String tableName = dbms().getQueryColumnSetWithPrefix(firstColumn);
        this.catalogOrSchema = dbms().getCatalogOrSchemaName(firstColumn);
        // definition is SELECT &lt;%=__COLUMN_NAMES__%> FROM &lt;%=__TABLE_NAME__%> GROUP BY
        // &lt;%=__GROUP_BY_ALIAS__%>
        String sqlExpr = dbms().fillGenericQueryWithColumnTableAndAlias(sqlGenericExpression.getBody(), selectItems, tableName, grpByClause);
        // handle data filter
        String stringDataFilter = ContextHelper.getDataFilterWithoutContext(cachedAnalysis);
        if (stringDataFilter == null) {
            stringDataFilter = PluginConstant.EMPTY_STRING;
        }
        sqlExpr = dbms().addWhereToStatement(sqlExpr, stringDataFilter);
        indicator.setInstantiatedExpression(BooleanExpressionHelper.createTdExpression(sqlGenericExpression.getLanguage(), sqlExpr));
        // MOD qiongli 2011-3-30 feature 19192.allow drill down for sql engine.
        if (ColumnsetPackage.eINSTANCE.getSimpleStatIndicator().isSuperTypeOf(indicator.eClass())) {
            SimpleStatIndicator simpleIndicator = (SimpleStatIndicator) indicator;
            // MOD TDQ-7287 lost some columns(type!=norminal) when view values in column set ana. yyin 20130514
            String columnsName = createSelect(columns, new ArrayList<String>());
            for (Indicator leafIndicator : simpleIndicator.getLeafIndicators()) {
                final Expression leafSqlGenericExpression = dbms().getSqlExpression(leafIndicator.getIndicatorDefinition());
                String leafSqlExpr = dbms().fillGenericQueryWithColumnTableAndAlias(leafSqlGenericExpression.getBody(), columnsName, tableName, grpByClause);
                leafSqlExpr = dbms().addWhereToStatement(leafSqlExpr, stringDataFilter);
                leafIndicator.setInstantiatedExpression(BooleanExpressionHelper.createTdExpression(leafSqlGenericExpression.getLanguage(), leafSqlExpr));
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) Expression(orgomg.cwm.objectmodel.core.Expression) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator)

Example 70 with TdColumn

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

the class AbstractComparisonLevel method upperCase.

private void upperCase(EObject eObject) {
    Package pckg = SwitchHelpers.PACKAGE_SWITCH.doSwitch(eObject);
    ColumnSet columnSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eObject);
    TdColumn column = SwitchHelpers.COLUMN_SWITCH.doSwitch(eObject);
    if (column != null) {
        // $NON-NLS-1$
        column.setName(column.getName() == null ? "" : column.getName().toUpperCase());
        // $NON-NLS-1$
        column.setLabel(column.getLabel() == null ? "" : column.getLabel().toUpperCase());
        column.getSqlDataType().setName(// $NON-NLS-1$
        column.getSqlDataType().getName() == null ? "" : column.getSqlDataType().getName().toUpperCase());
        // $NON-NLS-1$
        column.setContentType(column.getContentType() == null ? "" : column.getContentType().toUpperCase());
        // $NON-NLS-1$
        column.setSourceType(column.getSourceType() == null ? "" : column.getSourceType().toUpperCase());
    } else if (pckg != null) {
        // $NON-NLS-1$
        pckg.setName(pckg.getName() == null ? "" : pckg.getName().toUpperCase());
    } else if (columnSet != null) {
        // $NON-NLS-1$
        columnSet.setName(columnSet.getName() == null ? "" : columnSet.getName().toUpperCase());
    }
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package)

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