use of org.talend.dataquality.analysis.ExecutionInformations 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.ExecutionInformations in project tdq-studio-se by Talend.
the class SQLPatternExplorerTest method setUp.
/**
* DOC msjian Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
UnitTestBuildHelper.initProjectStructure();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
ITDQItemService tdqService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
tdqService.createDQStructor();
}
sqlPatternExplorer = new SQLPatternExplorer();
// mock setEntity
SqlPatternMatchingIndicator indicator = creatSqlPatternMatchingIndicator();
Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(indicator);
ana.setResults(createAnalysisResult);
sqlPatternExplorer.setAnalysis(ana);
// $NON-NLS-1$ //$NON-NLS-2$
ChartDataEntity chartDataEntity = new ChartDataEntity(indicator, "name1", "1");
chartDataEntity.setLabelNull(false);
// $NON-NLS-1$
chartDataEntity.setKey("name1");
sqlPatternExplorer.setEnitty(chartDataEntity);
IndicatorDefinition definition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody("SELECT * FROM tbi.customer ");
// $NON-NLS-1$
expression.setLanguage("SQL");
definition.getSqlGenericExpression().add(expression);
indicator.setIndicatorDefinition(definition);
indicator.getInstantiatedExpressions().add(expression);
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method setExecutionInfoInAnalysisResult.
/**
* set the execution info of analysis.
*
* @param analysis - which need to update the execution number
* @param isRunAnaResultok - the running result of the analysis is ok or not
* @param errorMessage - the error message
*/
public static void setExecutionInfoInAnalysisResult(Analysis analysis, boolean isRunAnaResultok, String errorMessage) {
final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
resultMetadata.setLastRunOk(isRunAnaResultok);
resultMetadata.setMessage(errorMessage);
resultMetadata.setExecutionNumber(resultMetadata.getExecutionNumber() + 1);
if (isRunAnaResultok) {
resultMetadata.setLastExecutionNumberOk(resultMetadata.getLastExecutionNumberOk() + 1);
}
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method setExecutionDateInAnalysisResult.
public static long setExecutionDateInAnalysisResult(Analysis analysis) {
final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
final long startime = System.currentTimeMillis();
resultMetadata.setExecutionDate(new Date(startime));
return startime;
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class ReportExecutor method execute.
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.IReportExecutor#execute(org.talend.dataquality.reports.TdReport)
*/
public ReturnCode execute(TdReport report, IProgressMonitor monitor) throws AnalysisExecutionException {
atLeastOneFailure = false;
long startTime = System.currentTimeMillis();
if (report.eIsProxy()) {
report = (TdReport) EObjectHelper.resolveObject(report);
}
EList<AnalysisMap> analysisMaps = report.getAnalysisMap();
StringBuilder strBuilder = new StringBuilder();
// loop on analysis maps is faster than loop on analyses
for (AnalysisMap analysisMap : analysisMaps) {
Analysis analysis = analysisMap.getAnalysis();
if (analysisMap.isMustRefresh()) {
if (analysis == null) {
return new ReturnCode(Messages.getString("ReportExecutor.CannotEvaluateNullAnalysis", report.getName()), // $NON-NLS-1$
false);
}
ReturnCode executeRc = AnalysisExecutorSelector.executeAnalysis(analysis, monitor);
if (executeRc.getMessage() != null && !StringUtils.EMPTY.equals(executeRc.getMessage().trim())) {
throw new AnalysisExecutionException(Messages.getString("ReportExecutor.failRunAnalysis", analysis.getName(), executeRc.getMessage()));
}
// ADD msjian TDQ-5952: we should close connections always
TdqAnalysisConnectionPool.closeConnectionPool(analysis);
// TDQ-5952~
if (!executeRc.isOk()) {
log.error("Failed to execute analysis " + analysis.getName() + ". Reason: " + executeRc.getMessage());
atLeastOneFailure = true;
}
if (log.isInfoEnabled()) {
strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " refreshed. State: " + executeRc.isOk() + "\n");
}
} else {
// skipped analysis
if (log.isInfoEnabled()) {
strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " skipped.\n");
}
}
}
// log execution
if (log.isInfoEnabled()) {
if (strBuilder.length() == 0) {
log.info("Generating reports for \"" + report.getName() + "\" without refreshing any analysis.");
} else {
log.info(strBuilder.toString());
}
}
long endTime = System.currentTimeMillis();
// fill in the execution informations
ExecutionInformations execInformations = ReportHelper.getExecutionInformations(report);
execInformations.setExecutionDate(new Date(startTime));
int duration = (int) (endTime - startTime);
execInformations.setExecutionDuration(duration);
execInformations.setExecutionNumber(execInformations.getExecutionNumber() + 1);
if (atLeastOneFailure) {
execInformations.setLastRunOk(false);
// $NON-NLS-1$
String err = Messages.getString("ReportExecutor.AnalysisExecutionFailed", report.getName());
execInformations.setMessage(err);
return new ReturnCode(err, false);
}
// else
execInformations.setLastRunOk(true);
execInformations.setLastExecutionNumberOk(execInformations.getExecutionNumber());
execInformations.setMessage(null);
return new ReturnCode();
}
Aggregations