Search in sources :

Example 16 with UserDefIndicator

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

the class DbmsLanguageTest method testGetSqlExpressionUserDefineCase1.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(org.talend.dataquality.indicators.definition.IndicatorDefinition)}
 * .
 */
@Test
public void testGetSqlExpressionUserDefineCase1() {
    // create 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);
    TdExpression newTdExp = // $NON-NLS-1$
    BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "MySQL", sql_1, null);
    newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
    indicatorDefinition.getSqlGenericExpression().add(newTdExp);
    TdExpression newTdExp_2 = // $NON-NLS-1$
    BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "SQL", sql_2, null);
    newTdExp_2.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
    indicatorDefinition.getSqlGenericExpression().add(newTdExp_2);
    DbmsLanguage dbms = getMysqlDbmsLanguage();
    Expression sqlExpression = dbms.getSqlExpression(indicatorDefinition);
    Assert.assertNotNull(sqlExpression);
    Assert.assertEquals(sql_1, sqlExpression.getBody());
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 17 with UserDefIndicator

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

the class DbmsLanguageTest method testGetSqlExpressionUserDefineCase2.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(org.talend.dataquality.indicators.definition.IndicatorDefinition)}
 * .
 */
@Test
public void testGetSqlExpressionUserDefineCase2() {
    // test for can not get sql expression(means: both database type and default type don't exist)
    // create 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);
    TdExpression newTdExp = // $NON-NLS-1$
    BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "Ingres", sql_1, null);
    newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
    indicatorDefinition.getSqlGenericExpression().add(newTdExp);
    DbmsLanguage dbms = getMysqlDbmsLanguage();
    Expression sqlExpression = dbms.getSqlExpression(indicatorDefinition);
    Assert.assertNull(sqlExpression);
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 18 with UserDefIndicator

use of org.talend.dataquality.indicators.sql.UserDefIndicator 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 19 with UserDefIndicator

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

the class UDIFactory method createUserDefIndicator.

public static Indicator createUserDefIndicator(IndicatorDefinition indicatorDefinition) {
    UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorParameters indicParams = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    userDefIndicator.setParameters(indicParams);
    userDefIndicator.setName(indicatorDefinition.getName());
    return userDefIndicator;
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 20 with UserDefIndicator

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

the class UDIFactory method createUserDefIndicator.

/**
 * DOC xqliu Comment method "createUserDefIndicator".
 *
 * @param indicatorDefinition
 * @param pattern
 * @return
 */
public static Indicator createUserDefIndicator(IndicatorDefinition indicatorDefinition, Pattern pattern) {
    UserDefIndicator indicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorParameters indicParams = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    Domain validData = DomainFactory.eINSTANCE.createDomain();
    validData.getPatterns().add(pattern);
    indicParams.setDataValidDomain(validData);
    indicator.setParameters(indicParams);
    indicator.setName(UDIHelper.getMatchingIndicatorName(indicatorDefinition, pattern));
    return indicator;
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Aggregations

UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)23 Test (org.junit.Test)9 TdExpression (org.talend.cwm.relational.TdExpression)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ArrayList (java.util.ArrayList)6 Indicator (org.talend.dataquality.indicators.Indicator)6 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)6 Analysis (org.talend.dataquality.analysis.Analysis)5 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)5 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)4 Expression (orgomg.cwm.objectmodel.core.Expression)4 Path (org.eclipse.core.runtime.Path)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 ItemState (org.talend.core.model.properties.ItemState)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)3