Search in sources :

Example 16 with ExecutionInformations

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"));
}
Also used : TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 17 with ExecutionInformations

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) CountsIndicator(org.talend.dataquality.indicators.CountsIndicator) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) RepositoryNode(org.talend.repository.model.RepositoryNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 18 with ExecutionInformations

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;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Date(java.util.Date)

Example 19 with ExecutionInformations

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);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) Indicator(org.talend.dataquality.indicators.Indicator) ValueIndicator(org.talend.dataquality.indicators.ValueIndicator)

Example 20 with ExecutionInformations

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 + ")");
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) Analysis(org.talend.dataquality.analysis.Analysis) Date(java.util.Date) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult)

Aggregations

ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)23 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)13 Analysis (org.talend.dataquality.analysis.Analysis)11 Test (org.junit.Test)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 Date (java.util.Date)5 TdColumn (org.talend.cwm.relational.TdColumn)5 TdTable (org.talend.cwm.relational.TdTable)5 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)5 TdExpression (org.talend.cwm.relational.TdExpression)4 Before (org.junit.Before)3 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)3 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)3 ReturnCode (org.talend.utils.sugars.ReturnCode)3 Package (orgomg.cwm.objectmodel.core.Package)3 SQLException (java.sql.SQLException)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)2