Search in sources :

Example 6 with ColumnSetMultiValueIndicator

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

the class ColumnSetAnalysisExecutor method createSqlStatement.

/*
     * (non-Jsdoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
     */
@Override
protected String createSqlStatement(Analysis analysis) {
    // MOD yyi 2011-02-22 17871:delimitefile
    if (isDelimitedFile) {
        return PluginConstant.EMPTY_STRING;
    }
    // ~
    this.cachedAnalysis = analysis;
    // $NON-NLS-1$
    StringBuilder sql = new StringBuilder("SELECT ");
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    // MOD yyi 2011-02-22 17871:delimitefile
    EList<ModelElement> analysedElements = null;
    for (Indicator indicator : indicators) {
        if (ColumnsetPackage.eINSTANCE.getColumnSetMultiValueIndicator().isSuperTypeOf(indicator.eClass())) {
            ColumnSetMultiValueIndicator colSetMultValIndicator = (ColumnSetMultiValueIndicator) indicator;
            if (analysedElements == null) {
                analysedElements = colSetMultValIndicator.getAnalyzedColumns();
            } else {
                analysedElements.addAll(colSetMultValIndicator.getAnalyzedColumns());
            }
        }
    }
    if (analysedElements == null || analysedElements.isEmpty()) {
        setError(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisExecutor.CannotCreateSQLStatement", analysis.getName()));
        return null;
    }
    // MOD yyi 2011-02-22 17871:delimitefile, indiactor changed
    final Iterator<ModelElement> iterator = analysedElements.iterator();
    while (iterator.hasNext()) {
        // for (ModelElement modelElement : analysedElements) {
        ModelElement modelElement = iterator.next();
        // --- preconditions
        TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
        if (col == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenElementIsNotColumn", modelElement));
            return null;
        }
        Classifier owner = col.getOwner();
        if (owner == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoOwnerFound", col.getName()));
        }
        ColumnSet colSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(owner);
        if (colSet == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoContainerFound", col.getName()));
            return null;
        }
        // select all the column to be prepare for drill down when user need.
        if (!analysis.getParameters().isStoreData()) {
            sql.append(this.quote(col.getName()));
            // append comma if more columns exist
            if (iterator.hasNext()) {
                sql.append(',');
            }
        }
    }
    TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysedElements.get(0));
    // select all the column to be prepare for drill down.
    if (analysis.getParameters().isStoreData()) {
        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues columnset
        EObject eContainer = firstColumn.eContainer();
        List<TdColumn> columnList = ColumnSetHelper.getColumns(SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer));
        // ~
        Iterator<TdColumn> iter = columnList.iterator();
        while (iter.hasNext()) {
            TdColumn column = iter.next();
            sql.append(this.quote(column.getName()));
            // append comma if more columns exist
            if (iter.hasNext()) {
                sql.append(',');
            }
        }
    }
    // add from clause
    sql.append(dbms().from());
    sql.append(dbms().getQueryColumnSetWithPrefix(firstColumn));
    // add where clause
    // --- get data filter
    ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
    handler.setAnalysis(analysis);
    String stringDataFilter = handler.getStringDataFilter();
    sql.append(GenericSQLHandler.WHERE_CLAUSE);
    String sqlStatement = sql.toString();
    sqlStatement = dbms().addWhereToStatement(sqlStatement, stringDataFilter);
    return sqlStatement;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Classifier(orgomg.cwm.objectmodel.core.Classifier) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) EObject(org.eclipse.emf.ecore.EObject)

Example 7 with ColumnSetMultiValueIndicator

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

the class DataExplorer method getAnalyzedElementName.

/**
 * Add qiongli handle ColumnSetMultiValueIndicator.
 *
 * @return
 */
protected String getAnalyzedElementName(Indicator ind) {
    if (ind.getAnalyzedElement() != null) {
        return dbmsLanguage.quote(ind.getAnalyzedElement().getName());
    }
    StringBuffer name = new StringBuffer(PluginConstant.EMPTY_STRING);
    EObject object = ind.eContainer();
    EList<ModelElement> eLs = null;
    if (object != null && object instanceof ColumnSetMultiValueIndicator) {
        eLs = ((ColumnSetMultiValueIndicator) object).getAnalyzedColumns();
    } else if (ind instanceof AllMatchIndicator) {
        eLs = ((AllMatchIndicator) ind).getAnalyzedColumns();
    }
    if (eLs != null && !eLs.isEmpty()) {
        for (ModelElement mColumn : eLs) {
            // $NON-NLS-1$
            name.append(dbmsLanguage.quote(mColumn.getName())).append(",");
        }
        if (eLs.size() > 0) {
            // $NON-NLS-1$
            return org.apache.commons.lang.StringUtils.removeEnd(name.toString(), ",");
        }
    }
    return name.toString();
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) EObject(org.eclipse.emf.ecore.EObject) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator)

Example 8 with ColumnSetMultiValueIndicator

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

the class ChangeConnectionAction method synAnalyzedElements.

private boolean synAnalyzedElements(AnalyzedElementSynDialog anaEleSynDialog, Analysis synAnalysis, Connection oldDataProvider, Connection newDataProv) {
    // Change connection uuid.
    Map<ModelElement, ModelElement> synEleMap = anaEleSynDialog == null ? null : anaEleSynDialog.getSynedEleMap();
    AnalysisBuilder anaBuilder = new AnalysisBuilder();
    anaBuilder.setAnalysis(synAnalysis);
    // Remove old dependencies.
    boolean isRemovedDependency = DependenciesHandler.getInstance().removeConnDependencyAndSave(analysisItem);
    if (!isRemovedDependency) {
        return false;
    }
    synAnalysis.getContext().setConnection(newDataProv);
    // Synchronize analysis result.
    EList<Indicator> indcList = synAnalysis.getResults().getIndicators();
    Indicator[] copiedIndArray = new Indicator[indcList.size()];
    System.arraycopy(indcList.toArray(), 0, copiedIndArray, 0, indcList.size());
    // MOD qiongli 2010-6-13,bug 12766:To column analysis, which has same
    // construct connection with before and maybe have not indicator
    boolean isExistSynedElement = false;
    AnalysisType analysisType = synAnalysis.getParameters().getAnalysisType();
    if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
        EList<ModelElement> meLs = synAnalysis.getContext().getAnalysedElements();
        ModelElement[] mes = new ModelElement[meLs.size()];
        System.arraycopy(meLs.toArray(), 0, mes, 0, meLs.size());
        synAnalysis.getContext().getAnalysedElements().clear();
        for (ModelElement me : mes) {
            if (synEleMap != null && synEleMap.get(me) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(me);
                synAnalysis.getContext().getAnalysedElements().add(newColumn);
                isExistSynedElement = true;
            }
        }
    }
    if (!isExistSynedElement) {
        synAnalysis.getContext().getAnalysedElements().clear();
    }
    // ~
    synAnalysis.getResults().getIndicators().clear();
    for (Indicator indicator : copiedIndArray) {
        // connection.
        if (indicator instanceof ColumnSetMultiValueIndicator) {
            ColumnSetMultiValueIndicator compositeInd = (ColumnSetMultiValueIndicator) indicator;
            ModelElement[] mes = new ModelElement[compositeInd.getAnalyzedColumns().size()];
            ((ColumnSetMultiValueIndicator) indicator).getAnalyzedColumns().toArray(mes);
            compositeInd.getAnalyzedColumns().clear();
            for (ModelElement me : mes) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    DataminingType dataminingType = MetadataHelper.getDataminingType((TdColumn) me);
                    if (dataminingType == null) {
                        dataminingType = MetadataHelper.getDefaultDataminingType(((TdColumn) me).getSqlDataType().getJavaDataType());
                    }
                    MetadataHelper.setDataminingType(dataminingType, newColumn);
                    compositeInd.getAnalyzedColumns().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
        } else if (indicator instanceof ColumnsCompareIndicator) {
            // Correlation compare
            ColumnsCompareIndicator compInd = (ColumnsCompareIndicator) indicator;
            if ((compInd.getColumnSetA() == null || compInd.getColumnSetA().size() == 0) || (compInd.getColumnSetB() == null || compInd.getColumnSetB().size() == 0)) {
                return false;
            }
            // Column set(Columns)
            ModelElement[] mesA = new ModelElement[compInd.getColumnSetA().size()];
            compInd.getColumnSetA().toArray(mesA);
            compInd.getColumnSetA().clear();
            for (ModelElement me : mesA) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    compInd.getColumnSetA().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
            ModelElement[] mesB = new ModelElement[compInd.getColumnSetB().size()];
            compInd.getColumnSetB().toArray(mesB);
            compInd.getColumnSetB().clear();
            for (ModelElement me : mesB) {
                if (synEleMap != null && synEleMap.get(me) != null) {
                    TdColumn newColumn = (TdColumn) synEleMap.get(me);
                    compInd.getColumnSetB().add(newColumn);
                    anaBuilder.addElementToAnalyze(newColumn, indicator);
                    isExistSynedElement = true;
                }
            }
            // Analyzed element(Table)
            ModelElement oldAnaEle = compInd.getAnalyzedElement();
            compInd.setAnalyzedElement(null);
            ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(mesA[0]);
            ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(mesB[0]);
            if (oldColSetA == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(mesA[0]) != null) {
                    compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesA[0])));
                }
            }
            if (oldColSetB == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(mesB[0]) != null) {
                    compInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(mesB[0])));
                }
            }
        } else if (indicator instanceof ColumnDependencyIndicator) {
            // ADD qiongli bug 0012766
            // Functional Dependency indicator
            ColumnDependencyIndicator funDepInd = (ColumnDependencyIndicator) indicator;
            if (funDepInd.getColumnA() == null || funDepInd.getColumnB() == null) {
                return false;
            }
            // Column A
            if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnA());
                funDepInd.setColumnA(newColumn);
                anaBuilder.addElementToAnalyze(newColumn, indicator);
                isExistSynedElement = true;
            }
            // Column B
            if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
                TdColumn newColumn = (TdColumn) synEleMap.get(funDepInd.getColumnB());
                funDepInd.setColumnB(newColumn);
                anaBuilder.addElementToAnalyze(newColumn, indicator);
                isExistSynedElement = true;
            }
            // Analyzed element(Table)
            ModelElement oldAnaEle = funDepInd.getAnalyzedElement();
            funDepInd.setAnalyzedElement(null);
            ColumnSet oldColSetA = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnA());
            ColumnSet oldColSetB = ColumnHelper.getColumnOwnerAsColumnSet(funDepInd.getColumnB());
            if (oldColSetA == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(funDepInd.getColumnA()) != null) {
                    funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnA())));
                }
            }
            if (oldColSetB == oldAnaEle) {
                if (synEleMap != null && synEleMap.get(funDepInd.getColumnB()) != null) {
                    funDepInd.setAnalyzedElement(ColumnHelper.getColumnOwnerAsColumnSet(synEleMap.get(funDepInd.getColumnB())));
                }
            }
        } else {
            ModelElement me = indicator.getAnalyzedElement();
            if (synEleMap != null && synEleMap.get(me) != null) {
                indicator.setAnalyzedElement(synEleMap.get(me));
                if (analysisType == AnalysisType.MULTIPLE_COLUMN) {
                    synAnalysis.getResults().getIndicators().add(indicator);
                } else {
                    anaBuilder.addElementToAnalyze(synEleMap.get(me), indicator);
                }
                isExistSynedElement = true;
            }
        }
    }
    return isExistSynedElement;
}
Also used : AnalysisType(org.talend.dataquality.analysis.AnalysisType) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnsCompareIndicator(org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) DataminingType(org.talend.dataquality.indicators.DataminingType) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) ColumnsCompareIndicator(org.talend.dataquality.indicators.columnset.ColumnsCompareIndicator) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder)

Example 9 with ColumnSetMultiValueIndicator

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

the class ColumnSetWizard method initCWMResourceBuilder.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.wizard.analysis.column.ColumnWizard#initCWMResourceBuilder()
     */
@Override
public ModelElement initCWMResourceBuilder() {
    Indicator indicator = getIndicator();
    if (indicator != null && indicator instanceof ColumnSetMultiValueIndicator) {
        ColumnSetMultiValueIndicator mvIndicator = (ColumnSetMultiValueIndicator) indicator;
        mvIndicator.setRowCountIndicator(IndicatorsFactory.eINSTANCE.createRowCountIndicator());
        mvIndicator.setDistinctCountIndicator(IndicatorsFactory.eINSTANCE.createDistinctCountIndicator());
        mvIndicator.setDuplicateCountIndicator(IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator());
        mvIndicator.setUniqueCountIndicator(IndicatorsFactory.eINSTANCE.createUniqueCountIndicator());
    }
    return super.initCWMResourceBuilder();
}
Also used : ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) Indicator(org.talend.dataquality.indicators.Indicator)

Aggregations

ColumnSetMultiValueIndicator (org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator)9 Indicator (org.talend.dataquality.indicators.Indicator)6 AllMatchIndicator (org.talend.dataquality.indicators.columnset.AllMatchIndicator)5 TdColumn (org.talend.cwm.relational.TdColumn)4 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 ArrayList (java.util.ArrayList)3 EObject (org.eclipse.emf.ecore.EObject)2 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)2 SimpleStatIndicator (org.talend.dataquality.indicators.columnset.SimpleStatIndicator)2 ReturnCode (org.talend.utils.sugars.ReturnCode)2 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)2 Connection (java.sql.Connection)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)1 ColumnSetIndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.ColumnSetIndicatorUnit)1 Analysis (org.talend.dataquality.analysis.Analysis)1 AnalysisType (org.talend.dataquality.analysis.AnalysisType)1 Domain (org.talend.dataquality.domain.Domain)1 DataminingType (org.talend.dataquality.indicators.DataminingType)1