Search in sources :

Example 26 with Analysis

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

the class TextStatisticsExplorerTest method testGetQueryMap.

/**
 * Test method for Text indicators with Hive connection,should don't have any menu items.
 */
@Test
public void testGetQueryMap() {
    AverageLengthIndicator averageLengthIndicator = IndicatorsFactory.eINSTANCE.createAverageLengthIndicator();
    TdColumn column = UnitTestBuildHelper.createRealTdColumn("NAME", "NAME", Types.VARCHAR);
    averageLengthIndicator.setAnalyzedElement(column);
    IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicatorParameters.setDateParameters(null);
    averageLengthIndicator.setParameters(indicatorParameters);
    IndicatorDefinition averageLengthIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    averageLengthIndicatorDef.setName("Average Length");
    averageLengthIndicator.setIndicatorDefinition(averageLengthIndicatorDef);
    Analysis analysis = UnitTestBuildHelper.createAndInitAnalysis();
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_NAME, "Teradata");
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_VERSION, "1");
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(averageLengthIndicator, "1", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("1");
    TextStatisticsExplorer textStatisticsExplorer = new TextStatisticsExplorer();
    textStatisticsExplorer.setAnalysis(analysis);
    textStatisticsExplorer.setEnitty(chartDataEntity);
    Map<String, String> queryMap = textStatisticsExplorer.getQueryMap();
    assertFalse(queryMap.isEmpty());
    assertEquals("-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose:  ;\n" + "-- Description:  ;\n" + "-- AnalyzedElement: NAME ;\n" + "-- Indicator: Average Length ;\n" + "-- Showing: View rows ;\n" + "SELECT t.* FROM(SELECT CAST(SUM( CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END) ) / (COUNT(NAME )*1.00)+0.99 as int) c,CAST(SUM( CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END) ) / (COUNT(NAME)*1.00) as int) f FROM TDQ_CALENDAR WHERE(NAME IS NOT NULL)) e, TDQ_CALENDAR t WHERE  CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END)  BETWEEN f AND c", queryMap.get("View rows"));
}
Also used : AverageLengthIndicator(org.talend.dataquality.indicators.AverageLengthIndicator) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Test(org.junit.Test)

Example 27 with Analysis

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

the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFiles.

@Test
public void testCheckIndicatorWithOutDependencyFiles() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/indicator_without_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
        }
    }
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertTrue(rc.isOk());
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
        }
    }
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 28 with Analysis

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

the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFilesAndBuiltIn.

@Test
public void testCheckIndicatorWithOutDependencyFilesAndBuiltIn() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/indicator_without_dep_builtin/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() == null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == null);
        }
    }
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertFalse(rc.isOk());
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 29 with Analysis

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

the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile_3.

// test for no column remained
@Test
public void testUpdateDependAnalysisOfDelimitedFile_3() throws IOException, URISyntaxException, PartInitException, BusinessException {
    // create a file connection
    DelimitedFileConnection fileConnection = ConnectionPackage.eINSTANCE.getConnectionFactory().createDelimitedFileConnection();
    // $NON-NLS-1$
    URL fileUrl = this.getClass().getResource("file1");
    MetadataTable metadataTable = UnitTestBuildHelper.initFileConnection(fileUrl, fileConnection);
    UnitTestBuildHelper.initColumns(metadataTable);
    IFile file = WorkspaceUtils.fileToIFile(new File(FileLocator.toFileURL(fileUrl).toURI()));
    IPath itemPath = file.getFullPath();
    Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
    // $NON-NLS-1$
    connectionProperty.setStatusCode("");
    connectionProperty.setLabel("file3");
    DelimitedFileConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDelimitedFileConnectionItem();
    connectionItem.setProperty(connectionProperty);
    connectionItem.setConnection(fileConnection);
    try {
        ProxyRepositoryFactory.getInstance().create(connectionItem, itemPath.removeFirstSegments(3).removeLastSegments(1));
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // create an analysis which use the columns in the file connection
    Analysis analysis = UnitTestBuildHelper.createRealAnalysis("Ana01", null, false);
    AnalysisContext context = AnalysisPackage.eINSTANCE.getAnalysisFactory().createAnalysisContext();
    context.setConnection(fileConnection);
    analysis.setContext(context);
    context.getAnalysedElements().addAll(metadataTable.getColumns());
    DependenciesHandler.getInstance().setDependencyOn(analysis, fileConnection);
    ElementWriterFactory.getInstance().createAnalysisWrite().save(analysis);
    // change the file's schema
    List<MetadataColumn> tempNewColumns = new ArrayList<MetadataColumn>();
    MetadataColumn name = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    name.setName("name2");
    name.setLabel("name2");
    tempNewColumns.add(name);
    MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    country.setName("country2");
    country.setLabel("country2");
    tempNewColumns.add(country);
    MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
    country1.setName("country1");
    country1.setLabel("country1");
    tempNewColumns.add(country1);
    metadataTable.getFeature().clear();
    metadataTable.getFeature().addAll(tempNewColumns);
    // before compare, the analysis has 5 analyzed elements
    Assert.assertEquals(5, analysis.getContext().getAnalysedElements().size());
    // call the tested method
    WorkbenchUtils.reloadMetadataOfDelimitedFile(metadataTable);
    List<MetadataColumn> afterCompareColumns = metadataTable.getColumns();
    // check the columns
    Assert.assertEquals(3, afterCompareColumns.size());
    Assert.assertEquals("name2", afterCompareColumns.get(0).getLabel());
    Assert.assertEquals("country2", afterCompareColumns.get(1).getLabel());
    Assert.assertEquals("country1", afterCompareColumns.get(2).getLabel());
    metadataTable.getColumns().clear();
    metadataTable.getColumns().addAll(afterCompareColumns);
    WorkbenchUtils.impactExistingAnalyses(fileConnection);
    // check the depended analysis
    EList<Dependency> clientDependencies = fileConnection.getSupplierDependency();
    for (Dependency dep : clientDependencies) {
        for (ModelElement mod : dep.getClient()) {
            if (!(mod instanceof Analysis)) {
                continue;
            }
            Analysis ana = (Analysis) mod;
            // assert the column with same name still in the analysis
            Assert.assertNotNull(ana.getContext().getAnalysedElements());
            // should be: only 2 with same name remained
            Assert.assertEquals(0, ana.getContext().getAnalysedElements().size());
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Dependency(orgomg.cwm.objectmodel.core.Dependency) URL(java.net.URL) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Property(org.talend.core.model.properties.Property) DelimitedFileConnectionItem(org.talend.core.model.properties.DelimitedFileConnectionItem) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with Analysis

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

the class ResourceViewLabelProviderTest method createAnalysis.

private void createAnalysis(String name, IPath createPath, Boolean isDelete) {
    Analysis analysis1 = AnalysisHelper.createAnalysis(name);
    TDQAnalysisItem item1 = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    org.talend.core.model.properties.Property property1 = PropertiesFactory.eINSTANCE.createProperty();
    property1.setId(EcoreUtil.generateUUID());
    property1.setItem(item1);
    property1.setLabel(analysis1.getName());
    item1.setProperty(property1);
    item1.setAnalysis(analysis1);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(isDelete);
    item1.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis1.setResults(analysisResult1);
    try {
        ProxyRepositoryFactory.getInstance().create(item1, createPath, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Aggregations

Analysis (org.talend.dataquality.analysis.Analysis)137 Test (org.junit.Test)36 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)36 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)30 ArrayList (java.util.ArrayList)28 Property (org.talend.core.model.properties.Property)28 Indicator (org.talend.dataquality.indicators.Indicator)27 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)27 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)26 PersistenceException (org.talend.commons.exception.PersistenceException)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)18 ReturnCode (org.talend.utils.sugars.ReturnCode)18 Dependency (orgomg.cwm.objectmodel.core.Dependency)18 TdColumn (org.talend.cwm.relational.TdColumn)16 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)16 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 IFile (org.eclipse.core.resources.IFile)14 File (java.io.File)12 IPath (org.eclipse.core.runtime.IPath)12