Search in sources :

Example 81 with TdExpression

use of org.talend.cwm.relational.TdExpression 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 82 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class IndicatorDefinitionFileHelper method addSqlExpression.

/**
 * keep the modify date
 *
 * @param definition
 * @param language
 * @param body
 * @param modifyDate
 * @return
 */
public static boolean addSqlExpression(IndicatorDefinition definition, String language, String body, String modifyDate) {
    if (null == definition) {
        return false;
    }
    TdExpression e = BooleanExpressionHelper.createTdExpression(language, body);
    e.setModificationDate(modifyDate);
    return definition.getSqlGenericExpression().add(e);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 83 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UDIUtils method createNewTdExpression.

/**
 * create New TdExpression.
 *
 * @param language
 * @param version
 * @param body
 * @return
 */
public static TdExpression createNewTdExpression(String language, String version, String body) {
    TdExpression newTdExp = BooleanExpressionHelper.createTdExpression(language, body, version);
    newTdExp.setModificationDate(getCurrentDateTime());
    return newTdExp;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 84 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class FileSystemImportWriter method mergeParserRule.

/**
 * for ParserRule: 1) replace the same name old rule with new rule; 2) will keep the old rule if new one don't
 * include the same name rule
 *
 * @param record imported modified parser rule
 * @param parserRuleItem the parser rule in the current studio
 */
protected void mergeParserRule(ItemRecord record, TDQBusinessRuleItem parserRuleItem) {
    // only when the parser rule is modified, do the save
    boolean isModified = false;
    // old object
    DQRule parserRule = parserRuleItem.getDqrule();
    Property parserRuleProp = parserRuleItem.getProperty();
    // new object
    DQRule recordRule = (DQRule) record.getElement();
    Property recordRuleProp = record.getProperty();
    // get expression list from record
    EList<TdExpression> importedExs = recordRule.getSqlGenericExpression();
    // for each expression:
    for (TdExpression importedEx : importedExs) {
        TdExpression systemExpression = null;
        for (TdExpression ex : parserRule.getSqlGenericExpression()) {
            if (ex.getName().equals(importedEx.getName())) {
                systemExpression = ex;
                break;
            }
        }
        if (systemExpression != null) {
            IndicatorDefinitionFileHelper.removeSqlExpressionByName(parserRule, importedEx.getName());
            IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
        } else {
            IndicatorDefinitionFileHelper.addSqlExpression(parserRule, importedEx.getName(), importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
        }
        isModified = true;
    }
    // for ParserRule Metadata
    if (parserRuleProp != null && recordRuleProp != null) {
        if (!StringUtils.isBlank(recordRuleProp.getPurpose())) {
            parserRuleProp.setPurpose(recordRuleProp.getPurpose());
        }
        if (!StringUtils.isBlank(recordRuleProp.getDescription())) {
            parserRuleProp.setDescription(recordRuleProp.getDescription());
        }
        parserRuleProp.setAuthor(recordRuleProp.getAuthor());
        parserRuleProp.setStatusCode(recordRuleProp.getStatusCode());
        isModified = true;
    }
    if (isModified) {
        ElementWriterFactory.getInstance().createdRuleWriter().save(parserRuleItem, false);
    }
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) Property(org.talend.core.model.properties.Property) DQRule(org.talend.dataquality.rules.DQRule)

Example 85 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class FileSystemImportWriter method mergePattern.

/**
 * when imported pattern is from lower version, even if it is modified, the "modify date" is still null, so, even if
 * the modify date is null ,still do the comparation. [for Pattern matadata(Purpose, Description, Author, Status):
 * 1) will replace old value with new value if new value is not blank; 2) will keep old value if new value is blank]
 *
 * @param record
 * @param patternItem
 */
protected void mergePattern(ItemRecord record, TDQPatternItem patternItem) {
    // only when the Si is modified, do the save
    boolean isModified = false;
    // old objects
    Pattern pattern = patternItem.getPattern();
    Property patternProp = patternItem.getProperty();
    // new objects
    Pattern recordPattern = (Pattern) record.getElement();
    Property recordProp = record.getProperty();
    // get expression list from record
    EList<PatternComponent> importComponents = recordPattern.getComponents();
    // for each expression:
    for (PatternComponent component : importComponents) {
        // if the modify date ==null, maybe it is from lower version, still do the compare
        TdExpression importEx = ((RegularExpression) component).getExpression();
        PatternComponent replaced = null;
        for (PatternComponent pComp : pattern.getComponents()) {
            TdExpression pex = ((RegularExpression) pComp).getExpression();
            if (importEx.getLanguage().equals(pex.getLanguage())) {
                replaced = pComp;
                break;
            }
        }
        // if new, add to SI
        if (replaced == null) {
            pattern.getComponents().add(createPatternComponent(component));
            isModified = true;
        } else {
            // if the expression are different: compare the modify date, make the SI keep the new one
            if (replaceExpression(((RegularExpression) replaced).getExpression(), importEx)) {
                pattern.getComponents().remove(replaced);
                pattern.getComponents().add(createPatternComponent(component));
                isModified = true;
            }
        }
    }
    // for Pattern Metadata
    if (patternProp != null && recordProp != null) {
        if (!StringUtils.isBlank(recordProp.getPurpose())) {
            patternProp.setPurpose(recordProp.getPurpose());
        }
        if (!StringUtils.isBlank(recordProp.getDescription())) {
            patternProp.setDescription(recordProp.getDescription());
        }
        patternProp.setAuthor(recordProp.getAuthor());
        patternProp.setStatusCode(recordProp.getStatusCode());
        isModified = true;
    }
    if (isModified) {
        ElementWriterFactory.getInstance().createPatternWriter().save(patternItem, false);
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Property(org.talend.core.model.properties.Property)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6