use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class SimpleStatisticsExplorerTest method testGetQueryMap.
/**
* Test method for {@link org.talend.dq.analysis.explore.SimpleStatisticsExplorer#getQueryMap()}.
*/
@Test
public void testGetQueryMap() {
Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
TdTable table = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
table.setName("TDQ_CALENDAR");
TdColumn column = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
column.setName("CAL_DATE");
TdSqlDataType tdsql = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
// $NON-NLS-1$
tdsql.setName("DATE");
tdsql.setJavaDataType(Types.DATE);
column.setSqlDataType(tdsql);
table.getOwnedElement().add(column);
column.setOwner(table);
// create user define indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
// $NON-NLS-1$
TdExpression newTdExp = BooleanExpressionHelper.createTdExpression("SQL", body, null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getViewRowsExpression().add(newTdExp);
// $NON-NLS-1$ //$NON-NLS-2$
ChartDataEntity chartDataEntity = new ChartDataEntity(userDefIndicator, "2012-06-05", "1");
chartDataEntity.setLabelNull(false);
// $NON-NLS-1$
chartDataEntity.setKey("2012-06-05");
userDefIndicator.setAnalyzedElement(column);
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(userDefIndicator);
userDefIndicator.setAnalyzedElement(column);
ana.setResults(createAnalysisResult);
SimpleStatisticsExplorer simpleStatisticsExplorer = new SimpleStatisticsExplorer();
Assert.assertTrue(simpleStatisticsExplorer.setAnalysis(ana));
simpleStatisticsExplorer.setEnitty(chartDataEntity);
Map<String, String> queryMap = simpleStatisticsExplorer.getQueryMap();
assertFalse(queryMap.isEmpty());
assertEquals(1, queryMap.size());
System.err.println(queryMap.get("View rows"));
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose: ;\n" + "-- Description: ;\n" + "-- AnalyzedElement: CAL_DATE ;\n" + "-- Indicator: user define ;\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"-- Showing: View rows ;\n" + "SELECT * FROM TDQ_CALENDAR ", // $NON-NLS-1$ //$NON-NLS-2$
queryMap.get("View rows"));
// test when is not sql engine
ana.getParameters().setExecutionLanguage(ExecutionLanguage.JAVA);
Map<String, String> queryMap_java = simpleStatisticsExplorer.getQueryMap();
assertFalse(queryMap_java.isEmpty());
assertEquals(1, queryMap_java.size());
// $NON-NLS-1$
assertEquals(null, queryMap_java.get("View rows"));
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class AbstractCommonActionProviderTest method createAnalysisNode.
private RepositoryNode createAnalysisNode(String name, IFolder folder, boolean isDelete) {
IPath createPath = Path.EMPTY;
if (folder != null) {
createPath = new Path(folder.getFullPath().lastSegment());
}
// connection
Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
createAnalysis.setName(name);
// ~connection
TDQAnalysisItem createAnalysisItem = org.talend.dataquality.properties.PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
org.talend.core.model.properties.Property createAnaProperty = PropertiesFactory.eINSTANCE.createProperty();
createAnaProperty.setId(EcoreUtil.generateUUID());
createAnaProperty.setItem(createAnalysisItem);
createAnaProperty.setLabel(createAnalysis.getName());
createAnalysisItem.setProperty(createAnaProperty);
createAnalysisItem.setAnalysis(createAnalysis);
ItemState createItemState = PropertiesFactory.eINSTANCE.createItemState();
createItemState.setDeleted(isDelete);
createAnalysisItem.setState(createItemState);
// Indicator
CountsIndicator createCountsIndicator = IndicatorsFactory.eINSTANCE.createCountsIndicator();
List<IRepositoryViewObject> all = null;
IndicatorDefinition createIndicatorDefinition = null;
try {
all = factory.getAll(ERepositoryObjectType.TDQ_SYSTEM_INDICATORS);
for (IRepositoryViewObject indicatorViewObject : all) {
if (indicatorViewObject.getLabel().equalsIgnoreCase("ROW COUNT")) {
// $NON-NLS-1$
createIndicatorDefinition = (IndicatorDefinition) PropertyHelper.getModelElement(indicatorViewObject.getProperty());
break;
}
}
} catch (PersistenceException e1) {
e1.printStackTrace();
Assert.fail(e1.getMessage());
}
createCountsIndicator.setIndicatorDefinition(createIndicatorDefinition);
AnalysisParameters createAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
createAnalysis.setContext(createAnalysisContext);
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(createCountsIndicator);
createAnalysis.setResults(createAnalysisResult);
createAnalysis.setParameters(createAnalysisParameters);
IRepositoryViewObject repViewObject = null;
try {
factory.create(createAnalysisItem, createPath, false);
repViewObject = factory.getLastVersion(createAnaProperty.getId());
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
RepositoryNode anaRepNode = new AnalysisRepNode(repViewObject, null, ENodeType.TDQ_REPOSITORY_ELEMENT, null);
// set the contentType for anaRepNode from its parentNode
setParentNode(anaRepNode, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT);
// ~
return anaRepNode;
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class ResourceUtils method createAnalysis.
public static Analysis createAnalysis(Indicator indicator) {
AnalysisParameters createAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
setUUID(null, createAnalysisParameters);
createAnalysisParameters.setAnalysisType(AnalysisType.MULTIPLE_COLUMN);
Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
setUUID(null, createAnalysis);
AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
setUUID(null, createAnalysisContext);
// $NON-NLS-1$
MetadataColumn createMetadataColumn = createMetadataColumn("columnName");
createAnalysisContext.getAnalysedElements().add(createMetadataColumn);
createAnalysis.setContext(createAnalysisContext);
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
setUUID(null, createAnalysisResult);
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
setUUID(null, createExecutionInformations);
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(indicator);
indicator.setAnalyzedElement(createMetadataColumn);
createAnalysis.setResults(createAnalysisResult);
createAnalysis.setParameters(createAnalysisParameters);
// $NON-NLS-1$
createAnalysis.setName("anaName");
// $NON-NLS-1$
MetadataHelper.setAuthor(createAnalysis, "shenze");
createAnalysis.setCreationDate(new Date(System.currentTimeMillis()));
setUUID(null, indicator);
return createAnalysis;
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class AnalysisExecutor method execute.
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.IAnalysisExecutor#execute(org.talend.dataquality.analysis.Analysis)
*/
public ReturnCode execute(final Analysis analysis) {
assert analysis != null;
// --- preconditions
if (!check(analysis)) {
AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, false, getErrorMessage());
return getReturnCode(false);
}
// --- creation time
final long startime = AnalysisExecutorHelper.setExecutionDateInAnalysisResult(analysis);
// MOD qiongli 2012-3-14 TDQ-4433,if import from low vesion and not import SystemIdicator,should initionlize
// these indicator.
initializeIndicators(analysis);
// --- create SQL statement
String sql = createSqlStatement(analysis);
if (sql == null) {
AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, false, getErrorMessage());
return getReturnCode(false);
}
// note: this feature is not supported now, if support, delete this
if (!StringUtils.isEmpty(getErrorMessage())) {
if ("EXCEL".equals(dbms().getDbmsName())) {
// $NON-NLS-1$
return getReturnCode(true);
}
AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, false, getErrorMessage());
return getReturnCode(false);
}
// ~
// --- run analysis
boolean ok = false;
try {
// catch any exception
if (this.continueRun()) {
// before run analysis need to clear old DB
if (AnalysisHelper.isJavaExecutionEngine(analysis)) {
MapDBManager.getInstance().deleteDB(analysis);
}
ok = runAnalysis(analysis, sql);
}
} catch (Exception e) {
ok = false;
log.error(e, e);
} finally {
// ADD msjian TDQ-5952: we should close connections always.
// after run analysis, close connection at once when don't need it
TdqAnalysisConnectionPool.closeConnectionPool(analysis);
// TDQ-5952~
if (AnalysisHelper.isJavaExecutionEngine(analysis)) {
MapDBManager.getInstance().closeDB(analysis);
}
}
if (getMonitor() != null) {
// $NON-NLS-1$
monitor.subTask(Messages.getString("AnalysisExecutor.UpdateAnalysisResut"));
}
// overwrite the current error messages
if (isLowMemory) {
// $NON-NLS-1$
setError(Messages.getString("Evaluator.OutOfMomory", usedMemory));
}
// --- set metadata information of analysis
AnalysisExecutorHelper.setExecutionInfoInAnalysisResult(analysis, ok, getErrorMessage());
// --- compute execution duration
if (this.continueRun()) {
long endtime = System.currentTimeMillis();
final ExecutionInformations resultMetadata = analysis.getResults().getResultMetadata();
resultMetadata.setExecutionDuration((int) (endtime - startime));
// MOD qiongli 2010-8-10, feature 14252
EList<Indicator> indicatorLs = analysis.getResults().getIndicators();
resultMetadata.setOutThreshold(false);
for (Indicator indicator : indicatorLs) {
if (hasOutThreshold(indicator)) {
resultMetadata.setOutThreshold(true);
break;
}
}
// ~
}
if (getMonitor() != null) {
getMonitor().worked(10);
}
return new ReturnCode(getErrorMessage(), ok);
}
use of org.talend.dataquality.analysis.ExecutionInformations in project tdq-studio-se by Talend.
the class AnalysisItemProvider method getText.
/**
*MODRLI
* This returns the label text for the adapted class.
*/
@Override
public String getText(Object object) {
Analysis analysis = ((Analysis) object);
String label = analysis.getName();
Date executionDate = null;
AnalysisResult analysisResult = analysis.getResults();
if (analysisResult != null) {
ExecutionInformations exeInformations = analysisResult.getResultMetadata();
if (exeInformations != null) {
executionDate = exeInformations.getExecutionDate();
}
}
String prefixDateString = null;
if (executionDate != null) {
prefixDateString = DateFormatUtils.getSimpleDateString(executionDate);
}
return label == null || label.length() == 0 ? getString("_UI_Analysis_type") : (prefixDateString == null ? label : label + " " + "(" + prefixDateString + ")");
}
Aggregations