Search in sources :

Example 21 with TdExpression

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

the class DbmsLanguageTest method testGetSqlExpressionDB2Case1.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionDB2Case1() {
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    // $NON-NLS-1$
    String db2Lang = "DB2";
    // $NON-NLS-1$
    String db2Body = "DB2 body";
    // $NON-NLS-1$
    String db2NTLang = "DB2/NT";
    // $NON-NLS-1$
    String db2NTBody = "DB2/NT body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    String language = db2NTLang;
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression2.setLanguage(db2Lang);
    tdExpression2.setBody(db2Body);
    sqlGenericExpression.add(tdExpression2);
    TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression3.setLanguage(db2NTLang);
    tdExpression3.setBody(db2NTBody);
    sqlGenericExpression.add(tdExpression3);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression3, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 22 with TdExpression

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

the class DbmsLanguageTest method testGetRegexpGetMssqlFromContainDefault.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
 */
@Test
public void testGetRegexpGetMssqlFromContainDefault() {
    // Pattern
    Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
    // ~Pattern
    // init java Expression data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage(SupportDBUrlType.JAVADEFAULTURL.getLanguage());
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createPattern.getComponents();
    components.add(createJavaRegularExpression);
    // ~init java Expression data
    // init sql Expression data
    RegularExpression createSqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createSqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createSqlTdExpression.setBody(SqlRegex);
    createSqlTdExpression.setLanguage(ExecutionLanguage.SQL.getName());
    createSqlRegularExpression.setExpression(createSqlTdExpression);
    createSqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    components = createPattern.getComponents();
    components.add(createSqlRegularExpression);
    // ~init sql Expression data
    // init mssql Expression data
    RegularExpression createMssqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createMssqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createMssqlTdExpression.setBody(MssqlRegex);
    createMssqlTdExpression.setLanguage(SupportDBUrlType.MSSQLDEFAULTURL.getLanguage());
    createMssqlRegularExpression.setExpression(createMssqlTdExpression);
    createMssqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    components = createPattern.getComponents();
    components.add(createMssqlRegularExpression);
    try {
        DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL);
        Assert.assertTrue(MssqlRegex.equalsIgnoreCase(dbms.getRegexp(createPattern).getBody()));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
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) Test(org.junit.Test)

Example 23 with TdExpression

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

the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase2.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionRedshiftCase2() {
    // TDQ-11558 msjian: test for get sql expresstion for redshift database when there is no redshift defined
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
    String postgresqlLang = SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage();
    // $NON-NLS-1$
    String postgresqlBody = "PostgreSQL body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression3.setLanguage(postgresqlLang);
    tdExpression3.setBody(postgresqlBody);
    sqlGenericExpression.add(tdExpression3);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression3, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 24 with TdExpression

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

the class DbmsLanguageTest method createPattern.

/**
 * create a default pattern for test
 *
 * @return
 */
private Pattern createPattern() {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    pattern.setName("My Pattern");
    RegularExpression regularExpr = PatternFactory.eINSTANCE.createRegularExpression();
    // $NON-NLS-1$
    TdExpression expression = createExpression("SQL");
    regularExpr.setExpression(expression);
    pattern.getComponents().add(regularExpr);
    RegularExpression regularExpr2 = PatternFactory.eINSTANCE.createRegularExpression();
    // $NON-NLS-1$
    TdExpression expression2 = createExpression("MySql");
    regularExpr2.setExpression(expression2);
    pattern.getComponents().add(regularExpr2);
    return pattern;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression)

Example 25 with TdExpression

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

the class DbmsLanguageTest method testGetSqlExpressionDB2Case2.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionDB2Case2() {
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    // $NON-NLS-1$
    String db2Lang = "DB2";
    // $NON-NLS-1$
    String db2Body = "DB2 body";
    // $NON-NLS-1$
    String db2NTLang = "DB2/NT";
    // $NON-NLS-1$
    String db2NTBody = "DB2/NT body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    String language = db2Lang;
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression2.setLanguage(db2Lang);
    tdExpression2.setBody(db2Body);
    sqlGenericExpression.add(tdExpression2);
    TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression3.setLanguage(db2NTLang);
    tdExpression3.setBody(db2NTBody);
    sqlGenericExpression.add(tdExpression3);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression2, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

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