Search in sources :

Example 1 with SqlPatternMatchingIndicator

use of org.talend.dataquality.indicators.SqlPatternMatchingIndicator 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);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdExpression(org.talend.cwm.relational.TdExpression) Analysis(org.talend.dataquality.analysis.Analysis) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ITDQItemService(org.talend.core.ITDQItemService) Before(org.junit.Before)

Example 2 with SqlPatternMatchingIndicator

use of org.talend.dataquality.indicators.SqlPatternMatchingIndicator in project tdq-studio-se by Talend.

the class PatternIndicatorFactory method createSqlPatternMatchingIndicator.

/**
 * Method "createSqlPatternMatchingIndicator".
 *
 * @param pattern the pattern from which the SqlPatternMatchingIndicator is created
 * @return the new SqlPatternMatchingIndicator with the same name as the pattern
 */
public static SqlPatternMatchingIndicator createSqlPatternMatchingIndicator(Pattern pattern) {
    SqlPatternMatchingIndicator patternMatchingIndicator = IndicatorsFactory.eINSTANCE.createSqlPatternMatchingIndicator();
    IndicatorParameters indicParams = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    Domain validData = DomainFactory.eINSTANCE.createDomain();
    validData.getPatterns().add(pattern);
    indicParams.setDataValidDomain(validData);
    patternMatchingIndicator.setParameters(indicParams);
    patternMatchingIndicator.setName(pattern.getName());
    return patternMatchingIndicator;
}
Also used : SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain)

Example 3 with SqlPatternMatchingIndicator

use of org.talend.dataquality.indicators.SqlPatternMatchingIndicator in project tdq-studio-se by Talend.

the class ModelElementAnalysisHandlerTest method testInitializeIndicator.

/**
 * Test method for
 * {@link org.talend.dq.analysis.ModelElementAnalysisHandler#initializeIndicator(org.talend.dataquality.indicators.Indicator)}
 * .
 */
@Test
public void testInitializeIndicator() {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    pattern.setName("old name");
    // give a pattern indicator in the analysis result, which name is different with its pattern's name
    SqlPatternMatchingIndicator patternMatchingIndicator = PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern);
    patternMatchingIndicator.setIndicatorDefinition(DefinitionFactory.eINSTANCE.createIndicatorDefinition());
    // $NON-NLS-1$
    pattern.setName("new name");
    // $NON-NLS-1$
    assertEquals("old name", patternMatchingIndicator.getName());
    // if the pattern's name is changed, then this method should use the newest name for the pattern indicator.
    maHandler.initializeIndicator(patternMatchingIndicator);
    // $NON-NLS-1$
    assertEquals("new name", patternMatchingIndicator.getName());
    // user indicator
    Indicator userIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    // $NON-NLS-1$
    userIndicator.setName("indicator name");
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    indicatorDefinition.setName("definition name");
    userIndicator.setIndicatorDefinition(indicatorDefinition);
    // $NON-NLS-1$
    assertEquals("indicator name", userIndicator.getName());
    // if the udi's name is changed, then this method should use the newest name for the udi.
    maHandler.initializeIndicator(userIndicator);
    // $NON-NLS-1$
    assertEquals("definition name", userIndicator.getName());
    // should not effect system indicators
    SimpleStatIndicator simpleStatIndicator = ColumnsetFactory.eINSTANCE.createSimpleStatIndicator();
    // $NON-NLS-1$
    simpleStatIndicator.setName("simple stat");
    simpleStatIndicator.setIndicatorDefinition(indicatorDefinition);
    assertNotSame(indicatorDefinition.getName(), simpleStatIndicator.getName());
    maHandler.initializeIndicator(simpleStatIndicator);
    assertNotSame(indicatorDefinition.getName(), simpleStatIndicator.getName());
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) Indicator(org.talend.dataquality.indicators.Indicator) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) Test(org.junit.Test)

Example 4 with SqlPatternMatchingIndicator

use of org.talend.dataquality.indicators.SqlPatternMatchingIndicator in project tdq-studio-se by Talend.

the class SQLPatternExplorerTest method creatSqlPatternMatchingIndicator.

private SqlPatternMatchingIndicator creatSqlPatternMatchingIndicator() {
    // create database construction
    TdColumn column = UnitTestBuildHelper.createRealTdColumn("lname", "lname", Types.VARCHAR);
    // create indicator
    SqlPatternMatchingIndicator indicator = IndicatorsFactory.eINSTANCE.createSqlPatternMatchingIndicator();
    indicator.setAnalyzedElement(column);
    IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicatorParameters.setDateParameters(null);
    indicator.setParameters(indicatorParameters);
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    pattern.setName("My Pattern");
    RegularExpression regularExpr = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody("'su%'");
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    regularExpr.setExpression(expression);
    pattern.getComponents().add(regularExpr);
    // create Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    indicatorParameters.setDataValidDomain(createDomain);
    indicatorParameters.getDataValidDomain().getPatterns().add(pattern);
    return indicator;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain)

Example 5 with SqlPatternMatchingIndicator

use of org.talend.dataquality.indicators.SqlPatternMatchingIndicator in project tdq-studio-se by Talend.

the class PatternStatisticeStateUtilTest method testGetUnitValueCase3.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.editor.preview.model.states.pattern.PatternStatisticeStateUtil#getUnitValue(org.talend.dataquality.indicators.Indicator, java.lang.Object)}
 * .
 * case3:normal SqlPatternMatchingIndicator case
 */
@Test
public void testGetUnitValueCase3() {
    PatternMatchingExt pMatchExt = null;
    SqlPatternMatchingIndicator sqlMatchingIndicator = IndicatorsFactoryImpl.eINSTANCE.createSqlPatternMatchingIndicator();
    sqlMatchingIndicator.setComputed(true);
    sqlMatchingIndicator.setMatchingValueCount(40l);
    sqlMatchingIndicator.setNotMatchingValueCount(50l);
    PatternMatchingExt unitValue = PatternStatisticeStateUtil.getUnitValue(sqlMatchingIndicator, pMatchExt);
    // $NON-NLS-1$
    Assert.assertEquals("Matching count value shoud be 40l", 40l, unitValue.getMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertEquals("Not matching count value shoud be 50l", 50l, unitValue.getNotMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertNotEquals("unitValue should not same with pMatchExt but it is not now", pMatchExt, unitValue);
}
Also used : SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) PatternMatchingExt(org.talend.dq.indicators.ext.PatternMatchingExt) Test(org.junit.Test)

Aggregations

SqlPatternMatchingIndicator (org.talend.dataquality.indicators.SqlPatternMatchingIndicator)5 Test (org.junit.Test)2 TdExpression (org.talend.cwm.relational.TdExpression)2 Domain (org.talend.dataquality.domain.Domain)2 Pattern (org.talend.dataquality.domain.pattern.Pattern)2 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)2 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)2 Before (org.junit.Before)1 ITDQItemService (org.talend.core.ITDQItemService)1 TdColumn (org.talend.cwm.relational.TdColumn)1 Analysis (org.talend.dataquality.analysis.Analysis)1 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)1 ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)1 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)1 Indicator (org.talend.dataquality.indicators.Indicator)1 SimpleStatIndicator (org.talend.dataquality.indicators.columnset.SimpleStatIndicator)1 PatternMatchingExt (org.talend.dq.indicators.ext.PatternMatchingExt)1 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)1