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"));
}
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());
}
}
}
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());
}
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());
}
}
}
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());
}
}
Aggregations