Search in sources :

Example 21 with RegularExpression

use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.

the class BooleanExpressionHelper method createRegularExpression.

/**
 * Method "createRegularExpression".
 *
 * @param language
 * @param expression
 * @param exprType
 * @return a regular expression of the given type (SQL like or regular expression)
 */
public static RegularExpression createRegularExpression(String language, String expression, ExpressionType exprType) {
    RegularExpression regexp = PatternFactory.eINSTANCE.createRegularExpression();
    regexp.setExpression(createTdExpression(language, expression));
    regexp.setExpressionType(exprType.getLiteral());
    return regexp;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression)

Example 22 with RegularExpression

use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.

the class DbmsLanguage method getExpression.

/**
 * Method "getExpression".
 *
 * @param patternComponent
 * @return the expression for the correct language or null
 */
public Expression getExpression(PatternComponent patternComponent) {
    if (patternComponent != null && patternComponent.eClass().equals(PatternPackage.eINSTANCE.getRegularExpression())) {
        RegularExpression regExp = (RegularExpression) patternComponent;
        Expression expression = regExp.getExpression();
        if (expression != null) {
            return getApplicable(expression);
        }
    }
    // not a regular expression
    return null;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression)

Example 23 with RegularExpression

use of org.talend.dataquality.domain.pattern.RegularExpression 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 24 with RegularExpression

use of org.talend.dataquality.domain.pattern.RegularExpression 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)

Example 25 with RegularExpression

use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.

the class PatternExplorerRealTest method testGetValidValuesStatement_2.

/**
 * Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidValuesStatement()}. when the test
 * for indicator is user define indicator
 */
@Test
public void testGetValidValuesStatement_2() {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicator.setIndicatorDefinition(indicatorDef);
    TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    udiTdExpression.setBody(ViewValidValues);
    indicatorDef.getViewValidValuesExpression().add(udiTdExpression);
    // 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.*`");
    TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTable.setName("table1");
    TableHelper.addColumn(createTdTable, element);
    Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    createCatalog.setName("catalog1");
    List<TdTable> tableList = new ArrayList<TdTable>();
    tableList.add(createTdTable);
    CatalogHelper.addTables(tableList, createCatalog);
    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);
    Assert.assertTrue(patternExplorer.setAnalysis(analysis));
    String clause = patternExplorer.getValidValuesStatement();
    // $NON-NLS-1$
    assertEquals("SELECT `lname` FROM `catalog1`.`table1` ", clause);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) Catalog(orgomg.cwm.resource.relational.Catalog) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdColumn(org.talend.cwm.relational.TdColumn) 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) Test(org.junit.Test)

Aggregations

RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)39 Pattern (org.talend.dataquality.domain.pattern.Pattern)26 TdExpression (org.talend.cwm.relational.TdExpression)18 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)17 Test (org.junit.Test)12 Domain (org.talend.dataquality.domain.Domain)12 Expression (orgomg.cwm.objectmodel.core.Expression)10 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)9 TdColumn (org.talend.cwm.relational.TdColumn)7 ArrayList (java.util.ArrayList)6 Analysis (org.talend.dataquality.analysis.Analysis)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 TdTable (org.talend.cwm.relational.TdTable)5 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)5 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)5 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)5 Catalog (orgomg.cwm.resource.relational.Catalog)5 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 PatternBuilder (org.talend.dq.pattern.PatternBuilder)3