Search in sources :

Example 36 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.

the class ImportMatchRuleAction method run.

@Override
public void run() {
    MatchRuleElementTreeSelectionDialog dialog = new MatchRuleElementTreeSelectionDialog(null, new DQRepositoryViewLabelProvider(), new ResourceViewContentProvider(), MatchRuleElementTreeSelectionDialog.MATCH_ANALYSIS_TYPE);
    List<String> inputColumnNames = new ArrayList<String>();
    Map<String, String> columnName2Type = new HashMap<String, String>();
    Analysis analysis = masterPage.getCurrentModelElement();
    EList<ModelElement> elements = analysis.getContext().getAnalysedElements();
    for (ModelElement me : elements) {
        inputColumnNames.add(me.getName());
        if (me instanceof MetadataColumn) {
            columnName2Type.put(me.getName(), ((MetadataColumn) me).getTalendType());
        }
    }
    dialog.setInputColumnNames(inputColumnNames);
    dialog.setColumnName2Type(columnName2Type);
    AnalysisResult anaResults = analysis.getResults();
    if (anaResults != null) {
        for (Indicator ind : anaResults.getIndicators()) {
            if (ind != null && ind instanceof RecordMatchingIndicator) {
                RecordMatchingIndicator rmInd = (RecordMatchingIndicator) ind;
                MatchRuleDefinition builtInMatchRuleDefinition = rmInd.getBuiltInMatchRuleDefinition();
                if (builtInMatchRuleDefinition != null) {
                    if (builtInMatchRuleDefinition.getBlockKeys() != null && builtInMatchRuleDefinition.getBlockKeys().size() > 0) {
                        List<String> blockKeyName = new ArrayList<String>();
                        for (BlockKeyDefinition blockKey : builtInMatchRuleDefinition.getBlockKeys()) {
                            blockKeyName.add(blockKey.getName());
                        }
                        dialog.setCurrentAnaBlockKeys(blockKeyName);
                    }
                    List<String> matchKeysName = new ArrayList<String>();
                    for (MatchRule matchRule : builtInMatchRuleDefinition.getMatchRules()) {
                        EList<MatchKeyDefinition> matchKeys = matchRule.getMatchKeys();
                        for (MatchKeyDefinition mkd : matchKeys) {
                            // same
                            if (!matchKeysName.contains(mkd.getName())) {
                                matchKeysName.add(mkd.getName());
                            }
                        }
                    }
                    dialog.setAnalysisCurrentMatchKeys(matchKeysName);
                    List<String> pdsdKeysName = new ArrayList<String>();
                    for (ParticularDefaultSurvivorshipDefinitions pdsd : builtInMatchRuleDefinition.getParticularDefaultSurvivorshipDefinitions()) {
                        pdsdKeysName.add(pdsd.getColumn());
                    }
                    dialog.setAnalysisCurrentParticularColumns(pdsdKeysName);
                }
            }
        }
    }
    dialog.create();
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        for (Object obj : results) {
            if (obj instanceof RuleRepNode) {
                RuleRepNode node = (RuleRepNode) obj;
                MatchRuleDefinition matchRule = (MatchRuleDefinition) node.getRule();
                if (matchRule != null) {
                    updateMatchRule(matchRule, dialog.isOverwrite());
                }
            }
        }
    }
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) HashMap(java.util.HashMap) MatchRuleElementTreeSelectionDialog(org.talend.dataprofiler.core.ui.dialog.MatchRuleElementTreeSelectionDialog) ResourceViewContentProvider(org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider) ArrayList(java.util.ArrayList) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) MatchRule(org.talend.dataquality.rules.MatchRule) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) RuleRepNode(org.talend.dq.nodes.RuleRepNode) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Analysis(org.talend.dataquality.analysis.Analysis) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) DQRepositoryViewLabelProvider(org.talend.dataprofiler.core.ui.views.provider.DQRepositoryViewLabelProvider)

Example 37 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.

the class AnalysisItemProvider method getText.

/**
 *MODRLI
 * This returns the label text for the adapted class.
 */
@Override
public String getText(Object object) {
    Analysis analysis = ((Analysis) object);
    String label = analysis.getName();
    Date executionDate = null;
    AnalysisResult analysisResult = analysis.getResults();
    if (analysisResult != null) {
        ExecutionInformations exeInformations = analysisResult.getResultMetadata();
        if (exeInformations != null) {
            executionDate = exeInformations.getExecutionDate();
        }
    }
    String prefixDateString = null;
    if (executionDate != null) {
        prefixDateString = DateFormatUtils.getSimpleDateString(executionDate);
    }
    return label == null || label.length() == 0 ? getString("_UI_Analysis_type") : (prefixDateString == null ? label : label + " " + "(" + prefixDateString + ")");
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) Analysis(org.talend.dataquality.analysis.Analysis) Date(java.util.Date) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult)

Example 38 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.

the class AnalysisBaseBuilder method createAnalysisResult.

private AnalysisResult createAnalysisResult() {
    AnalysisResult result = AnalysisFactory.eINSTANCE.createAnalysisResult();
    // create its metadata
    ExecutionInformations executionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    result.setResultMetadata(executionInformations);
    return result;
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult)

Example 39 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.

the class AnalysisImpl method basicSetResults.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetResults(AnalysisResult newResults, NotificationChain msgs) {
    AnalysisResult oldResults = results;
    results = newResults;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AnalysisPackage.ANALYSIS__RESULTS, oldResults, newResults);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult)

Example 40 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.

the class IndicatorEvaluator method executeSqlQuery.

@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
    ReturnCode ok = new ReturnCode(true);
    // check analyzed columns
    Set<String> columns = getAnalyzedElements();
    // feature 0010630 zshen:Make order unify which columns and columnName in the sqlStatement.mssqlOdbc need do
    // this
    List<String> columnlist = sortColumnName(columns, sqlStatement);
    if (columnlist.isEmpty()) {
        // $NON-NLS-1$
        ok.setReturnCode(Messages.getString("IndicatorEvaluator.DefineAnalyzedColumns"), false);
        return ok;
    }
    // ADD xqliu 2010-07-27 bug 13826
    Map<String, String> columnlistMap = buildColumnListMap(columnlist);
    // ~ 13826
    // create query statement
    // feature 0010630 zshen: Tables are not found when using Excel with ODBC connection
    Statement statement = createStatement();
    // MOD xqliu 2009-02-09 bug 6237
    if (continueRun()) {
        if (log.isInfoEnabled()) {
            // $NON-NLS-1$
            log.info("Executing query: " + sqlStatement);
        }
        statement.execute(sqlStatement);
    }
    // get the results
    ResultSet resultSet = statement.getResultSet();
    if (resultSet == null) {
        // $NON-NLS-1$
        String mess = Messages.getString("Evaluator.NoResultSet", sqlStatement);
        log.warn(mess);
        ok.setReturnCode(mess, false);
        statement.close();
        return ok;
    }
    // MOD qiongli TDQ-7282,check invalid judi.if there are invalid judis,return false code and show message later.
    ok = getMessageForInvalidJUDIs();
    int columnCount = resultSet.getMetaData().getColumnCount();
    int maxNumberRows = analysis.getParameters().getMaxNumberRows();
    // MOD mzhao feature: 12919, add capability to dill down data on Java engine.
    AnalysisResult anaResult = analysis.getResults();
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = anaResult.getIndicToRowMap();
    indicToRowMap.clear();
    int recordIncrement = 0;
    // --- for each row
    int columnListSize = columnlist.size();
    label: while (resultSet.next()) {
        // feature 0010630 zshen: dislodge the Qualifiers from name of the column
        for (int i = 0; i < columnListSize; i++) {
            // MOD xqliu 2010-07-27 bug 13826
            String col = columnlist.get(i);
            List<Indicator> indicators = getIndicators(col);
            col = columnlistMap.get(col);
            // --- get content of column
            Object object = ResultSetUtils.getBigObject(resultSet, col);
            // FIXME this will slow down a lot the computation
            if (object != null && !(object instanceof String) && object.toString().indexOf("TIMESTAMP") > -1) {
                // $NON-NLS-1$
                object = resultSet.getTimestamp(col);
            }
            // TDQ-11299: fix the ClassCastException: java.sql.Date cannot be cast to java.lang.String
            if (object instanceof Date) {
                if (object instanceof Time) {
                    object = new TalendFormatTime((Time) object);
                } else {
                    object = new TalendFormatDate((Date) object);
                }
            }
            // --- give row to handle to indicators
            for (Indicator indicator : indicators) {
                // MOD xqliu 2009-02-09 bug 6237
                if (!continueRun()) {
                    break label;
                }
                // Added yyin 20120608 TDQ-3589
                if (indicator instanceof DuplicateCountIndicator) {
                    ((DuplicateCountIndicator) indicator).handle(object, resultSet, columnCount);
                } else {
                    // ~
                    indicator.handle(object);
                // ~MOD mzhao feature: 12919
                }
                AnalyzedDataSet analyzedDataSet = indicToRowMap.get(indicator);
                if (analyzedDataSet == null) {
                    analyzedDataSet = AnalysisFactory.eINSTANCE.createAnalyzedDataSet();
                    indicToRowMap.put(indicator, analyzedDataSet);
                    analyzedDataSet.setDataCount(maxNumberRows);
                    analyzedDataSet.setRecordSize(0);
                }
                // should store data for dirll down
                if (analysis.getParameters().isStoreData()) {
                    // current indicator is need to store the data
                    if (indicator.mustStoreRow()) {
                        List<Object[]> valueObjectList = initDataSet(indicator, indicToRowMap, object);
                        // MOD zshen add another loop to insert all of columnValue on the row into indicator.
                        recordIncrement = valueObjectList.size();
                        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues
                        // columnset
                        ColumnSet doSwitch = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement().eContainer());
                        List<TdColumn> columnList = ColumnSetHelper.getColumns(doSwitch);
                        List<Object> inputRowList = new ArrayList<Object>();
                        for (int j = 0; j < columnCount; j++) {
                            String newcol = columnList.get(j).getName();
                            Object newobject = ResultSetUtils.getBigObject(resultSet, newcol);
                            // same format as result page.
                            if (newobject instanceof Date) {
                                if (newobject instanceof Time) {
                                    newobject = new TalendFormatTime((Time) newobject);
                                } else {
                                    newobject = new TalendFormatDate((Date) newobject);
                                }
                            }
                            if (indicator.isUsedMapDBMode()) {
                                inputRowList.add(newobject == null ? PluginConstant.NULL_STRING : newobject);
                                continue;
                            } else {
                                if (recordIncrement < maxNumberRows) {
                                    // data.
                                    if (recordIncrement < valueObjectList.size()) {
                                        // decide whether need to
                                        // increase
                                        // current array.
                                        valueObjectList.get(recordIncrement)[j] = newobject;
                                    } else {
                                        Object[] valueObject = new Object[columnCount];
                                        valueObject[j] = newobject;
                                        valueObjectList.add(valueObject);
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                        if (indicator.isUsedMapDBMode()) {
                            MapDBUtils.handleDrillDownData(object, inputRowList, indicator);
                        }
                    // ~
                    } else if (indicator instanceof UniqueCountIndicator && analysis.getResults().getIndicToRowMap().get(indicator).getData() != null) {
                        List<Object[]> removeValueObjectList = analysis.getResults().getIndicToRowMap().get(indicator).getData();
                        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues
                        // columnset
                        ColumnSet doSwitch = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement().eContainer());
                        List<TdColumn> columnElementList = ColumnSetHelper.getColumns(doSwitch);
                        int offsetting = columnElementList.indexOf(indicator.getAnalyzedElement());
                        for (Object[] dataObject : removeValueObjectList) {
                            if (dataObject[offsetting].equals(object)) {
                                removeValueObjectList.remove(dataObject);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    // --- release resultset
    resultSet.close();
    // --- release statement
    statement.close();
    // --- close connection
    getConnection().close();
    return ok;
}
Also used : UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) Time(java.sql.Time) TalendFormatTime(org.talend.dataquality.indicators.mapdb.TalendFormatTime) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) TalendFormatTime(org.talend.dataquality.indicators.mapdb.TalendFormatTime) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) TalendFormatDate(org.talend.dataquality.indicators.mapdb.TalendFormatDate) Statement(java.sql.Statement) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) FormatFreqPieIndicator(org.talend.dataquality.indicators.FormatFreqPieIndicator) MaxLengthIndicator(org.talend.dataquality.indicators.MaxLengthIndicator) Indicator(org.talend.dataquality.indicators.Indicator) MinLengthIndicator(org.talend.dataquality.indicators.MinLengthIndicator) PatternLowFreqIndicator(org.talend.dataquality.indicators.PatternLowFreqIndicator) PatternFreqIndicator(org.talend.dataquality.indicators.PatternFreqIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Date(java.util.Date) TalendFormatDate(org.talend.dataquality.indicators.mapdb.TalendFormatDate) TdColumn(org.talend.cwm.relational.TdColumn)

Aggregations

AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)40 Analysis (org.talend.dataquality.analysis.Analysis)26 Test (org.junit.Test)15 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)15 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)14 ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)13 Property (org.talend.core.model.properties.Property)11 PersistenceException (org.talend.commons.exception.PersistenceException)10 ItemState (org.talend.core.model.properties.ItemState)10 Path (org.eclipse.core.runtime.Path)8 TdColumn (org.talend.cwm.relational.TdColumn)8 TdTable (org.talend.cwm.relational.TdTable)8 Indicator (org.talend.dataquality.indicators.Indicator)8 IPath (org.eclipse.core.runtime.IPath)7 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ReturnCode (org.talend.utils.sugars.ReturnCode)7 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)6 Before (org.junit.Before)5 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)4