Search in sources :

Example 36 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class DbmsLanguage method getTableCountQueryExpression.

/**
 * Get the query Expression for one table of column
 *
 * @param column
 * @param where
 * @return
 */
public Expression getTableCountQueryExpression(MetadataTable metadataTable, String where) {
    Schema parentSchema = SchemaHelper.getParentSchema(metadataTable);
    Catalog parentCatalog = CatalogHelper.getParentCatalog(metadataTable);
    if (parentSchema != null) {
        parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
    }
    String schemaName = parentSchema == null ? null : parentSchema.getName();
    String catalogName = parentCatalog == null ? null : parentCatalog.getName();
    String qualifiedName = this.toQualifiedName(catalogName, schemaName, metadataTable.getName());
    Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
    String expressionBody = getQuerySql(COUNT_ASTERISK, qualifiedName, where);
    queryExpression.setBody(expressionBody);
    queryExpression.setLanguage(this.getDbmsName());
    return queryExpression;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 37 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class DbmsLanguage method getColumnQueryExpression.

/**
 * Get the query Expression for one column
 *
 * @param column
 * @param where
 * @return
 */
public Expression getColumnQueryExpression(TdColumn column, String where) {
    ModelElement columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
    Schema parentSchema = SchemaHelper.getParentSchema(columnSet);
    Catalog parentCatalog = CatalogHelper.getParentCatalog(columnSet);
    if (parentSchema != null) {
        parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
    }
    String schemaName = parentSchema == null ? null : parentSchema.getName();
    String catalogName = parentCatalog == null ? null : parentCatalog.getName();
    String qualifiedName = this.toQualifiedName(catalogName, schemaName, columnSet.getName());
    Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
    String expressionBody = getQuerySql(column.getName(), qualifiedName, where);
    queryExpression.setBody(expressionBody);
    queryExpression.setLanguage(this.getDbmsName());
    return queryExpression;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 38 with Expression

use of orgomg.cwm.objectmodel.core.Expression 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 39 with Expression

use of orgomg.cwm.objectmodel.core.Expression 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 40 with Expression

use of orgomg.cwm.objectmodel.core.Expression 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

Expression (orgomg.cwm.objectmodel.core.Expression)71 TdExpression (org.talend.cwm.relational.TdExpression)42 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)37 Test (org.junit.Test)25 Domain (org.talend.dataquality.domain.Domain)14 ArrayList (java.util.ArrayList)13 TdColumn (org.talend.cwm.relational.TdColumn)11 Pattern (org.talend.dataquality.domain.pattern.Pattern)10 Catalog (orgomg.cwm.resource.relational.Catalog)10 Indicator (org.talend.dataquality.indicators.Indicator)9 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Analysis (org.talend.dataquality.analysis.Analysis)7 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)6