use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutorTest method testCreateSqlStatement_1.
/**
* when there are some catelog
* {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
* .
*/
@Test
public void testCreateSqlStatement_1() {
Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
analysis.setContext(context);
TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTable.setName("tableName");
tdColumn.setOwner(tdTable);
// $NON-NLS-1$
tdColumn.setName("columnName");
AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
analysisPara.setStoreData(false);
analysis.setParameters(analysisPara);
context.getAnalysedElements().add(tdColumn);
AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
analysisResult.setResultMetadata(info);
analysis.setResults(analysisResult);
// mock(Catalog.class);
Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
catalog.setName("catalogName");
tdTable.setNamespace(catalog);
DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getLanguage()));
analysis.getContext().setConnection(createConnection);
ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
// $NON-NLS-1$
assertEquals("SELECT `columnName` FROM `catalogName`.`tableName`", columnAnalysisExecutor.createSqlStatement(analysis));
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutorTest method testCreateSqlStatement_2.
/**
* when there are some schema.
* {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
* .
*/
@Test
public void testCreateSqlStatement_2() {
Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
analysis.setContext(context);
TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTable.setName("tableName");
tdColumn.setOwner(tdTable);
// $NON-NLS-1$
tdColumn.setName("columnName");
AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
analysisPara.setStoreData(false);
analysis.setParameters(analysisPara);
context.getAnalysedElements().add(tdColumn);
AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
analysisResult.setResultMetadata(info);
analysis.setResults(analysisResult);
// mock(Schema.class);
Package schema = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
// $NON-NLS-1$
schema.setName("schemaName");
tdTable.setNamespace(schema);
// mock(Catalog.class);
Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
catalog.setName("catalogName");
schema.setNamespace(catalog);
DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MSSQLDEFAULTURL.getLanguage()));
analysis.getContext().setConnection(createConnection);
ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
assertEquals("SELECT columnName FROM catalogName.schemaName.tableName", // $NON-NLS-1$
columnAnalysisExecutor.createSqlStatement(analysis));
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutorTest method setUp.
/**
* DOC zshen Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// create analysis element
TdColumn testTdColumn = RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
testTdColumn.setName("columnName");
// testAnalysisResult.setModelElement(testTdColumn);
// create sqlDataType
TdSqlDataType testTdSqlDataType = RelationalFactory.eINSTANCE.createTdSqlDataType();
testTdColumn.setSqlDataType(testTdSqlDataType);
testTdSqlDataType.setJavaDataType(DataminingType.NOMINAL_VALUE);
// create TdTable
TdTable testTdTable = RelationalFactory.eINSTANCE.createTdTable();
testTdColumn.setNamespace(testTdTable);
// $NON-NLS-1$
testTdTable.setName("generateTable");
// create connection
DatabaseConnection testDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(testDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getDBKey());
// create catalog
Catalog testCatalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
testCatalog.setName("TBI");
testTdTable.setNamespace(testCatalog);
testCatalog.setNamespace(testDatabaseConnection);
testCatalog.getDataManager().add(testDatabaseConnection);
// create analysis
testAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
// create Analaysis result
AnalysisResult testAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
testAnalysis.setResults(testAnalysisResult);
// create analysis parameter
AnalysisParameters testAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
testAnalysis.setParameters(testAnalysisParameters);
// create analysis Content
AnalysisContext testAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
testAnalysis.setContext(testAnalysisContext);
testAnalysisContext.setConnection(testDatabaseConnection);
// create row count indicatorDefinition
testIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// $NON-NLS-1$
testIndicatorDefinition.setLabel("Pattern Frequency Table");
// create row count indicator
testFrequencyIndicator = IndicatorsFactory.eINSTANCE.createPatternFreqIndicator();
testAnalysisResult.getIndicators().add(testFrequencyIndicator);
testFrequencyIndicator.setAnalyzedElement(testTdColumn);
testFrequencyIndicator.setIndicatorDefinition(testIndicatorDefinition);
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class MultiColumnAnalysisExecutorTest method setUp.
@Before
public void setUp() throws Exception {
analysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
analysis.setContext(context);
// mock(Catalog.class);
Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
catalog.setName("tbi");
TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTable.setName("customer");
tdTable.setNamespace(catalog);
TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
tdColumn.setOwner(tdTable);
// $NON-NLS-1$
tdColumn.setName("date_accnt_opened");
tdColumn.setContentType(DataminingType.INTERVAL.getName());
TdColumn tdColumn2 = RelationalFactory.eINSTANCE.createTdColumn();
tdColumn2.setOwner(tdTable);
// $NON-NLS-1$
tdColumn2.setName("product_id");
tdColumn2.setContentType(DataminingType.INTERVAL.getName());
AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
analysisPara.setStoreData(false);
// set analysis type is columnset
analysisPara.setAnalysisType(AnalysisType.COLUMN_SET);
analysis.setParameters(analysisPara);
context.getAnalysedElements().add(tdColumn);
context.getAnalysedElements().add(tdColumn2);
AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
analysisResult.setResultMetadata(info);
simpleStatIndicator = ColumnsetFactory.eINSTANCE.createSimpleStatIndicator();
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody(// $NON-NLS-1$
"SELECT <%=__COLUMN_NAMES__%> FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%> GROUP BY <%=__GROUP_BY_ALIAS__%>");
// $NON-NLS-1$
expression.setLanguage("SQL");
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
indicatorDefinition.getSqlGenericExpression().add(expression);
simpleStatIndicator.setIndicatorDefinition(indicatorDefinition);
// $NON-NLS-1$
simpleStatIndicator.getDateFunctions().add("");
// $NON-NLS-1$
simpleStatIndicator.getNumericFunctions().add("");
simpleStatIndicator.setDataminingType(DataminingType.NOMINAL);
simpleStatIndicator.getAnalyzedColumns().add(tdColumn);
simpleStatIndicator.getAnalyzedColumns().add(tdColumn2);
analysisResult.getIndicators().add(simpleStatIndicator);
analysis.setResults(analysisResult);
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class SummaryStastictisExplorerRealTest method testGetQueryMap.
/**
* Test method for {@link org.talend.dq.analysis.explore.SummaryStastictisExplorer#getQueryMap()}.
*/
@Test
public void testGetQueryMap() {
// testing code for SQL Engine here
SummaryStastictisExplorer summaryExplorerSql = new SummaryStastictisExplorer();
Analysis analysisReal = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisParameters analysisParametersReal = AnalysisFactory.eINSTANCE.createAnalysisParameters();
analysisParametersReal.setExecutionLanguage(ExecutionLanguage.SQL);
analysisReal.setParameters(analysisParametersReal);
AnalysisContext analysisContextReal = AnalysisFactory.eINSTANCE.createAnalysisContext();
DataManager dataManagerReal = SoftwaredeploymentFactory.eINSTANCE.createDataManager();
analysisContextReal.setConnection(dataManagerReal);
analysisReal.setContext(analysisContextReal);
summaryExplorerSql.setAnalysis(analysisReal);
TdColumn tdColumnReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
TdTable tdTableReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTableReal.setName("tableName");
tdColumnReal.setOwner(tdTableReal);
// $NON-NLS-1$
tdColumnReal.setName("id");
TdSqlDataType tdsqlReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
// $NON-NLS-1$
tdsqlReal.setName("Integer");
tdColumnReal.setSqlDataType(tdsqlReal);
// test for MeanIndicator
MeanIndicator meanIndicator = IndicatorsFactory.eINSTANCE.createMeanIndicator();
meanIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition meanIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
meanIndicatorDef.setName("Mean");
meanIndicator.setIndicatorDefinition(meanIndicatorDef);
ChartDataEntity entityReal = new ChartDataEntity();
// $NON-NLS-1$
entityReal.setValue("0");
entityReal.setIndicator(meanIndicator);
summaryExplorerSql.setEnitty(entityReal);
Map<String, String> queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for MedianIndicator
MedianIndicator medianIndicator = IndicatorsFactory.eINSTANCE.createMedianIndicator();
medianIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition medianIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
medianIndicatorDef.setName("Median");
medianIndicator.setIndicatorDefinition(medianIndicatorDef);
entityReal.setIndicator(medianIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 1);
// test for IQRIndicator
MaxValueIndicator maxValueIndicator = IndicatorsFactory.eINSTANCE.createMaxValueIndicator();
// $NON-NLS-1$
maxValueIndicator.setValue("80");
IndicatorDefinition maxValueIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
maxValueIndicatorDef.setName("Maximum");
maxValueIndicator.setIndicatorDefinition(maxValueIndicatorDef);
MinValueIndicator minValueIndicator = IndicatorsFactory.eINSTANCE.createMinValueIndicator();
// $NON-NLS-1$
minValueIndicator.setValue("20");
IndicatorDefinition minValueIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
minValueIndicatorDef.setName("Minimum");
minValueIndicator.setIndicatorDefinition(minValueIndicatorDef);
IQRIndicator iqrIndicator = IndicatorsFactory.eINSTANCE.createIQRIndicator();
iqrIndicator.setUpperValue(maxValueIndicator);
iqrIndicator.setLowerValue(minValueIndicator);
iqrIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition iqrIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
iqrIndicatorDef.setName("Inter Quartile Range");
iqrIndicator.setIndicatorDefinition(iqrIndicatorDef);
entityReal.setIndicator(iqrIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 2);
// test for LowerQuartileIndicator
LowerQuartileIndicator lowerQuartileIndicator = IndicatorsFactory.eINSTANCE.createLowerQuartileIndicator();
lowerQuartileIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition lowerQuartileIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
lowerQuartileIndicatorDef.setName("Lower Quartile");
lowerQuartileIndicator.setIndicatorDefinition(lowerQuartileIndicatorDef);
entityReal.setIndicator(lowerQuartileIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 1);
// test for UpperQuartileIndicator
UpperQuartileIndicator upperQuartileIndicator = IndicatorsFactory.eINSTANCE.createUpperQuartileIndicator();
upperQuartileIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition upperQuartileIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
upperQuartileIndicatorDef.setName("Upper Quartile");
upperQuartileIndicator.setIndicatorDefinition(upperQuartileIndicatorDef);
entityReal.setIndicator(upperQuartileIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 1);
// test for RangeIndicator
RangeIndicator rangeIndicator = IndicatorsFactory.eINSTANCE.createRangeIndicator();
rangeIndicator.setUpperValue(maxValueIndicator);
rangeIndicator.setLowerValue(minValueIndicator);
rangeIndicator.setAnalyzedElement(tdColumnReal);
IndicatorDefinition rangeIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
rangeIndicatorDef.setName("Range");
rangeIndicator.setIndicatorDefinition(rangeIndicatorDef);
entityReal.setIndicator(rangeIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 2);
// test for MinValueIndicator
minValueIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(minValueIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 1);
// test for MaxValueIndicator
maxValueIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(maxValueIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.size() == 1);
// testing code for Java Engine here
analysisParametersReal.setExecutionLanguage(ExecutionLanguage.JAVA);
analysisReal.setParameters(analysisParametersReal);
summaryExplorerSql.setAnalysis(analysisReal);
// test for MeanIndicator
meanIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(meanIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for MedianIndicator
medianIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(medianIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for IQRIndicator
iqrIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(iqrIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for LowerQuartileIndicator
lowerQuartileIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(lowerQuartileIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for UpperQuartileIndicator
upperQuartileIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(upperQuartileIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for RangeIndicator
rangeIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(rangeIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for MinValueIndicator
minValueIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(minValueIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
// test for MaxValueIndicator
maxValueIndicator.setAnalyzedElement(tdColumnReal);
entityReal.setIndicator(maxValueIndicator);
summaryExplorerSql.setEnitty(entityReal);
queryMap = summaryExplorerSql.getQueryMap();
Assert.assertTrue(queryMap.isEmpty());
}
Aggregations