Search in sources :

Example 66 with TdExpression

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

the class RegexpMatchingIndicatorImplTest method testGetRegexsuccess.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
 */
@Test
public void testGetRegexsuccess() {
    // RegexpMatchingIndicator
    RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // ~RegexpMatchingIndicator
    // IndicatorParameters
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // ~IndicatorParameters
    // Domain
    Domain createDomain = DomainFactory.eINSTANCE.createDomain();
    EList<Pattern> patterns = createDomain.getPatterns();
    // ~Domain
    // Pattern
    Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
    Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
    patterns.add(createJavaPattern);
    patterns.add(createSQLPattern);
    patterns.add(createMSSQLPattern);
    // ~Pattern
    // init java Pattern data
    RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createJavaTdExpression.setBody(JavaRegex);
    createJavaTdExpression.setLanguage("Java");
    createJavaRegularExpression.setExpression(createJavaTdExpression);
    createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    EList<PatternComponent> components = createJavaPattern.getComponents();
    components.add(createJavaRegularExpression);
    // ~init java Pattern data
    createIndicatorParameters.setDataValidDomain(createDomain);
    createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
    // call getRegex()
    String regexResult = createRegexpMatchingIndicator.getRegex();
    String JavaRegex2 = JavaRegex.substring(1, JavaRegex.length() - 1);
    // ~call getRegex()
    Assert.assertTrue(JavaRegex2.equalsIgnoreCase(regexResult));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 67 with TdExpression

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

the class MultiColumnAnalysisExecutorTest method testCreateSqlStatement_3.

/**
 * test for leaf indicator's drill down sql , with interval type. MOD TDQ-7287 lost some columns(type!=norminal)
 * when view values in column set ana. yyin 20130514
 */
@Test
public void testCreateSqlStatement_3() {
    DistinctCountIndicator distinctCountIndicator = IndicatorsFactory.eINSTANCE.createDistinctCountIndicator();
    IndicatorDefinition definition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    String body = "SELECT COUNT(*) FROM (SELECT DISTINCT <%=__COLUMN_NAMES__%> FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>) A";
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody(body);
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    definition.getSqlGenericExpression().add(expression);
    distinctCountIndicator.setIndicatorDefinition(definition);
    simpleStatIndicator.setDistinctCountIndicator(distinctCountIndicator);
    simpleStatIndicator.setDataminingType(DataminingType.NOMINAL);
    MultiColumnAnalysisExecutor multiColumnAnalysisExecutor = new MultiColumnAnalysisExecutor();
    // $NON-NLS-1$
    assertEquals("", multiColumnAnalysisExecutor.createSqlStatement(analysis));
    String viewValues = "SELECT COUNT(*) FROM (SELECT DISTINCT date_accnt_opened,product_id FROM tbi.customer ) A";
    assertEquals(viewValues, simpleStatIndicator.getLeafIndicators().get(0).getInstantiatedExpressions("SQL").getBody());
}
Also used : DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Test(org.junit.Test)

Example 68 with TdExpression

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

the class TableAnalysisSqlExecutorTest method testCreateSqlStatementCase2.

/**
 * Test method for
 * {@link org.talend.dq.analysis.TableAnalysisSqlExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * . case 1:the where rule have join conditions
 */
@Test
public void testCreateSqlStatementCase2() {
    // $NON-NLS-1$
    String sql = "select count(*) from table where 1=1";
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody(sql);
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    testWhereRuleIndicatorDefinition.getSqlGenericExpression().add(expression);
    JoinElement createJoinElement = RulesFactory.eINSTANCE.createJoinElement();
    // $NON-NLS-1$
    createJoinElement.setColumnAliasA("colA");
    // $NON-NLS-1$
    createJoinElement.setColumnAliasB("colB");
    // $NON-NLS-1$
    createJoinElement.setTableAliasA("tabA");
    // $NON-NLS-1$
    createJoinElement.setTableAliasB("tabB");
    TdColumn createTdColumnA = RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    createTdColumnA.setName("colA");
    TdTable createTdTableA = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTableA.setName("tableA");
    createTdColumnA.setOwner(createTdTableA);
    TdColumn createTdColumnB = RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    createTdColumnB.setName("colB");
    TdTable createTdTableB = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTableB.setName("tableB");
    createTdColumnB.setOwner(createTdTableB);
    createJoinElement.setColA(createTdColumnA);
    createJoinElement.setColB(createTdColumnB);
    testWhereRuleIndicatorDefinition.getJoins().add(createJoinElement);
    TableAnalysisSqlExecutor tableAnalysisSqlExecutor = new TableAnalysisSqlExecutor();
    String actualSqlStatement = tableAnalysisSqlExecutor.createSqlStatement(testAnalysis);
    Assert.assertEquals(StringUtils.EMPTY, actualSqlStatement);
    EList<Expression> instantiatedExpressions = testWhereRuleIndicator.getInstantiatedExpressions();
    Assert.assertNotNull(instantiatedExpressions);
    Assert.assertEquals(1, instantiatedExpressions.size());
    Assert.assertEquals(sql, instantiatedExpressions.get(0).getBody());
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Test(org.junit.Test)

Example 69 with TdExpression

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

the class FrequencyStatisticsExplorerTest method testGetFreqRowsStatement_4.

/**
 * Test method for {@link org.talend.dq.analysis.explore.FrequencyStatisticsExplorer#getFreqRowsStatement()} case_3:
 * for UDIndicatorDefinition
 */
@Test
public void testGetFreqRowsStatement_4() {
    // create database construction
    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 indicator
    UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
    // $NON-NLS-1$
    indicatorDefinition.setName("user define count");
    userDefIndicator.setName(indicatorDefinition.getName());
    userDefIndicator.setIndicatorDefinition(indicatorDefinition);
    TdExpression newTdExp = // $NON-NLS-1$
    BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "SQL", "SELECT * FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>", // $NON-NLS-1$
    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");
    assertFalse(chartDataEntity.isLabelNull());
    userDefIndicator.setAnalyzedElement(column);
    IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicatorParameters.setDateParameters(null);
    userDefIndicator.setParameters(indicatorParameters);
    assertNull(indicatorParameters.getDateParameters());
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    createAnalysisResult.getIndicators().add(userDefIndicator);
    userDefIndicator.setAnalyzedElement(column);
    ana.setResults(createAnalysisResult);
    freqExp = new FrequencyStatisticsExplorer();
    freqExp.setAnalysis(ana);
    freqExp.setEnitty(chartDataEntity);
    String clause = freqExp.getFreqRowsStatement();
    // $NON-NLS-1$
    assertEquals("SELECT * FROM TDQ_CALENDAR ", clause);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Example 70 with TdExpression

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

the class PatternExplorerRealTest method setUp.

/**
 * DOC zshen Comment method "setUp".
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    // create pattern parameter
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicator.setParameters(createIndicatorParameters);
    Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
    createIndicatorParameters.setDataValidDomain(createDomain);
    Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
    createDomain.getPatterns().add(createPattern);
    RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
    createPattern.getComponents().add(createPatternComponent);
    TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    createPatternComponent.setExpression(createTdExpression);
    createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createTdExpression.setBody("`su.*`");
    ModelElement element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    indicator.setAnalyzedElement(element);
    Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
    createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createIndiExpression.setBody("SELECT *  FROM `tbi`.`customer`  WHERE (customer.lname = \"sunny\")");
    indicator.setInstantiatedExpression(createIndiExpression);
    Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
    AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
    analysis.setContext(createAnalysisContext);
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
    createAnalysisContext.setConnection(createDatabaseConnection);
    patternExplorer.setAnalysis(analysis);
    ChartDataEntity cdEntity = new ChartDataEntity();
    cdEntity.setIndicator(indicator);
    patternExplorer.setEnitty(cdEntity);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Domain(org.talend.dataquality.domain.Domain) Before(org.junit.Before)

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