Search in sources :

Example 26 with RowCountIndicator

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

the class ItemRecordTest method testLoadProperty.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.imex.model.ItemRecord#loadProperty()}.
 *
 * @throws PersistenceException
 */
@Test
public void testLoadProperty() throws PersistenceException {
    chooseRightProject();
    // $NON-NLS-1$
    Property analysisProperty = createAnalysis("ItemRecordTestanalysis1");
    TDQAnalysisItem item = (TDQAnalysisItem) analysisProperty.getItem();
    Analysis analysis = item.getAnalysis();
    AnalysisResult createAnalysisResult = analysis.getResults();
    Assert.assertEquals(0, createAnalysisResult.getIndicators().size());
    // create Indicator
    RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
    String rowCountPropertyID = EcoreUtil.generateUUID();
    // $NON-NLS-1$
    saveIndicatorDefintion(rowCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition1");
    rowCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(rowCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
    // $NON-NLS-1$
    Assert.assertNotNull("Row count indicator definition should not be null", rowCountIndicator.getIndicatorDefinition());
    Assert.assertEquals("ItemRecordWithRefreshedTestIndicatorDefinition1", // $NON-NLS-1$
    rowCountIndicator.getIndicatorDefinition().getLabel());
    createAnalysisResult.getIndicators().add(rowCountIndicator);
    Assert.assertEquals(1, createAnalysisResult.getIndicators().size());
    ReturnCode saveAnalysis = saveAnalysis(analysis);
    Assert.assertEquals(1, ((TDQAnalysisItem) analysisProperty.getItem()).getAnalysis().getResults().getIndicators().size());
    // $NON-NLS-1$
    Assert.assertTrue("The analysis first time saving is not work", saveAnalysis.isOk());
    File analysisFile = WorkspaceUtils.ifileToFile(PropertyHelper.getItemFile(analysisProperty));
    ItemRecord itemRecord = new ItemRecord(analysisFile);
    Assert.assertEquals(1, itemRecord.getDependencySet().size());
    // create Indicator
    NullCountIndicator nullCountIndicator = IndicatorsFactory.eINSTANCE.createNullCountIndicator();
    String nullCountPropertyID = EcoreUtil.generateUUID();
    // $NON-NLS-1$
    saveIndicatorDefintion(nullCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition2");
    nullCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(nullCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
    analysis = item.getAnalysis();
    analysis.getResults().getIndicators().add(nullCountIndicator);
    ReturnCode saveAnalysis2 = saveAnalysis(analysis);
    // $NON-NLS-1$
    Assert.assertTrue("The analysis second time saving is not work", saveAnalysis2.isOk());
    // get last resource so that the dependecy will not changed
    itemRecord = new ItemRecord(analysisFile);
    Assert.assertEquals(1, itemRecord.getDependencySet().size());
    // after clear the resource will be lastest so that the dependency is added
    ItemRecord.clear();
    itemRecord = new ItemRecord(analysisFile);
    Assert.assertEquals(2, itemRecord.getDependencySet().size());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Property(org.talend.core.model.properties.Property) File(java.io.File) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 27 with RowCountIndicator

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

the class IndicatorHelperTest method testGetRowCountIndicator2.

/**
 * Test method for
 * {@link org.talend.dataquality.helpers.IndicatorHelper#getRowCountIndicator(orgomg.cwm.objectmodel.core.ModelElement, java.util.Map)}
 * . get RowCountIndicator
 */
@Test
public void testGetRowCountIndicator2() {
    // TdColumn
    TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
    // ~
    // List
    List<Indicator> list = null;
    // ~
    // Map
    Map<ModelElement, List<Indicator>> elementToIndicator = new HashMap<ModelElement, List<Indicator>>();
    elementToIndicator.put(column1, list);
    // ~
    RowCountIndicator rowCountIndicator2 = IndicatorHelper.getRowCountIndicator(column1, elementToIndicator);
    assert (rowCountIndicator2 == null);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Test(org.junit.Test)

Example 28 with RowCountIndicator

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

the class ColumnAnalysisSqlExecutor method addElements2IndicatorsMapping.

/**
 * add mapping of analyzed elements to their indicators.
 *
 * @param elementToIndicator
 * @param indicator
 */
protected void addElements2IndicatorsMapping(Map<ModelElement, List<Indicator>> elementToIndicator, Indicator indicator) {
    // to set rowcount for each element
    if (indicator instanceof RowCountIndicatorsAdapter) {
        RowCountIndicatorsAdapter indicator1 = (RowCountIndicatorsAdapter) indicator;
        Set<RowCountIndicator> rowCountIndiSet = indicator1.getRowCountIndiSet();
        for (RowCountIndicator rowCountInd : rowCountIndiSet) {
            MultiMapHelper.addUniqueObjectToListMap(rowCountInd.getAnalyzedElement(), indicator, elementToIndicator);
        }
    } else {
        MultiMapHelper.addUniqueObjectToListMap(indicator.getAnalyzedElement(), indicator, elementToIndicator);
    }
}
Also used : RowCountIndicatorsAdapter(org.talend.dataquality.helpers.RowCountIndicatorsAdapter) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator)

Example 29 with RowCountIndicator

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

the class ColumnAnalysisSqlExecutor method setRowCountAndNullCount.

/**
 * DOC scorreia Comment method "setRowCountAndNullCount".
 *
 * @param elementToIndicator
 */
protected void setRowCountAndNullCount(Map<ModelElement, List<Indicator>> elementToIndicator) {
    Set<ModelElement> analyzedElements = elementToIndicator.keySet();
    for (ModelElement modelElement : analyzedElements) {
        // get row count indicator
        RowCountIndicator rowCount = IndicatorHelper.getRowCountIndicator(modelElement, elementToIndicator);
        // get null count indicator
        NullCountIndicator nullCount = IndicatorHelper.getNullCountIndicator(modelElement, elementToIndicator);
        List<Indicator> list = elementToIndicator.get(modelElement);
        for (Indicator ind : list) {
            // set row count value to each indicator
            if (rowCount != null && needPercentage(ind)) {
                ind.setCount(rowCount.getCount());
            }
            // set null count value to each indicator
            if (nullCount != null) {
                ind.setNullCount(nullCount.getNullCount());
            }
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator)

Example 30 with RowCountIndicator

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

the class CreateDuplicatesAnalysisAction method run.

@Override
public void run() {
    ReturnCode success = new ReturnCode(true);
    if (this.getColumnsMap() == null || this.getColumnsMap().isEmpty() || this.getConnection() == null) {
        return;
    }
    try {
        Set<ColumnSet> keySet = this.getColumnsMap().keySet();
        for (ColumnSet cs : keySet) {
            List<TdColumn> columns = this.getColumnsMap().get(cs);
            // create the analysis
            Analysis analysis = null;
            AnalysisBuilder analysisBuilder = new AnalysisBuilder();
            boolean analysisInitialized = analysisBuilder.initializeAnalysis(getAnalysisName(cs), AnalysisType.MULTIPLE_COLUMN);
            if (analysisInitialized) {
                analysis = analysisBuilder.getAnalysis();
            }
            fillMetadataToAnalysis(analysis, createDefaultAnalysisParameter(cs));
            // add Connection into the Analysis Context
            analysis.getContext().setConnection(this.getConnection());
            for (TdColumn theColumn : columns) {
                // add TdColumn into the Analysis Context
                analysis.getContext().getAnalysedElements().add(theColumn);
                // create Row Count Indicator
                RowCountIndicator rcIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
                rcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(rcIndicator);
                analysis.getResults().getIndicators().add(rcIndicator);
                // create Duplicate Count Indicator
                DuplicateCountIndicator dcIndicator = IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator();
                dcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(dcIndicator);
                analysis.getResults().getIndicators().add(dcIndicator);
            }
            // create dependencies
            DependenciesHandler.getInstance().setDependencyOn(analysis, this.getConnection());
            // set the domain
            for (Domain domain : analysis.getParameters().getDataFilter()) {
                domain.setName(analysis.getName());
            }
            // set execution language
            analysis.getParameters().setExecutionLanguage(ExecutionLanguage.SQL);
            // save the analysis
            RepositoryNode analysisRepNode = (RepositoryNode) RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS);
            IFolder folder = WorkbenchUtils.getFolder(analysisRepNode);
            AnalysisWriter analysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
            TypedReturnCode<Object> create = analysisWriter.create(analysis, folder);
            if (create.isOk()) {
                // refresh the RepositoryView
                CorePlugin.getDefault().refreshDQView(analysisRepNode);
                // open the editor
                AnalysisRepNode anaRepNode = RepositoryNodeHelper.recursiveFindAnalysis(analysis);
                AnalysisItemEditorInput analysisEditorInput = new AnalysisItemEditorInput(anaRepNode);
                IRepositoryNode connectionRepNode = RepositoryNodeHelper.recursiveFind(this.getConnection());
                analysisEditorInput.setConnectionNode(connectionRepNode);
                CorePlugin.getDefault().openEditor(analysisEditorInput, AnalysisEditor.class.getName());
            } else {
                success.setOk(false);
                success.setMessage(create.getMessage());
            }
        }
    // for
    } catch (Exception e) {
        success.setOk(false);
        success.setMessage(e.getMessage());
    }
    if (!success.isOk()) {
        MessageUI.openError(success.getMessage());
    }
}
Also used : DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TdColumn(org.talend.cwm.relational.TdColumn) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) Domain(org.talend.dataquality.domain.Domain) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)33 Indicator (org.talend.dataquality.indicators.Indicator)12 Test (org.junit.Test)11 NullCountIndicator (org.talend.dataquality.indicators.NullCountIndicator)10 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)9 ArrayList (java.util.ArrayList)8 DistinctCountIndicator (org.talend.dataquality.indicators.DistinctCountIndicator)7 UniqueCountIndicator (org.talend.dataquality.indicators.UniqueCountIndicator)7 PersistenceException (org.talend.commons.exception.PersistenceException)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)6 List (java.util.List)5 AverageLengthIndicator (org.talend.dataquality.indicators.AverageLengthIndicator)5 BlankCountIndicator (org.talend.dataquality.indicators.BlankCountIndicator)5 TdColumn (org.talend.cwm.relational.TdColumn)4 DefValueCountIndicator (org.talend.dataquality.indicators.DefValueCountIndicator)4 InvalidRegCodeCountIndicator (org.talend.dataquality.indicators.InvalidRegCodeCountIndicator)4 MaxLengthIndicator (org.talend.dataquality.indicators.MaxLengthIndicator)4 MaxValueIndicator (org.talend.dataquality.indicators.MaxValueIndicator)4 MeanIndicator (org.talend.dataquality.indicators.MeanIndicator)4