Search in sources :

Example 6 with WhereRule

use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.

the class AnalysisExecutorHelper method checkIndicatorWithChild.

/**
 * DOC zhao Comment method "checkIndicatorWithChild".
 *
 * @param indicator
 * @return
 */
private static ReturnCode checkIndicatorWithChild(Indicator indicator) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    if (indicator.getBuiltInIndicatorDefinition() != null) {
        return rc;
    }
    // Get indicator definition from dependent file
    IndicatorDefinition dependentDefinition = indicator.getIndicatorDefinition();
    if (isDependentFileExist(dependentDefinition)) {
        IndicatorDefinition deepCopiedDefinition;
        if (dependentDefinition instanceof WhereRule) {
            deepCopiedDefinition = copyWhereRule((WhereRule) dependentDefinition);
        } else {
            deepCopiedDefinition = EObjectHelper.deepCopy(dependentDefinition);
        }
        // Hot copy to built-in definition.
        deepCopiedDefinition.getSupplierDependency().clear();
        // TDQ-10737 Because 'BuiltInIndicatorDefinition' is a containment reference, need to Clear these 3 non-containment
        // reference list
        deepCopiedDefinition.getCategories().clear();
        deepCopiedDefinition.getAggregatedDefinitions().clear();
        deepCopiedDefinition.getSubCategories().clear();
        indicator.setBuiltInIndicatorDefinition(deepCopiedDefinition);
        EMFUtil.saveResource(indicator.eResource());
    } else {
        IndicatorDefinition builtInDefinition = indicator.getBuiltInIndicatorDefinition();
        if (builtInDefinition == null) {
            // $NON-NLS-1$
            rc.setMessage(Messages.getString("AnalysisExecutor.BuiltInNoIndicators"));
            rc.setOk(false);
            return rc;
        } else {
            indicator.setIndicatorDefinition(null);
        }
    }
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) WhereRule(org.talend.dataquality.rules.WhereRule) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 7 with WhereRule

use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.

the class WhereRuleHandler method getWhereRule.

/**
 * DOC xqliu Comment method "getWhereRule".
 *
 * @param name
 * @return
 */
public WhereRule getWhereRule(String name) {
    WhereRule result = null;
    List<? extends ModelElement> rules = DQRuleResourceFileHelper.getInstance().getAllElement();
    for (ModelElement rule : rules) {
        if (rule instanceof WhereRule && name.equals(rule.getName())) {
            result = (WhereRule) rule;
            break;
        }
    }
    return result;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) WhereRule(org.talend.dataquality.rules.WhereRule)

Example 8 with WhereRule

use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.

the class EResourceConstantTest method testGetTypedConstantItem_2.

/**
 * Test method for
 * {@link org.talend.resource.EResourceConstant#getTypedConstant(org.talend.core.model.properties.Item)}. test for
 * where rule
 */
@Test
public void testGetTypedConstantItem_2() {
    WhereRule whereRule = mock(WhereRule.class);
    ruleItem.setDqrule(whereRule);
    EResourceConstant rc = EResourceConstant.getTypedConstant(ruleItem);
    Assert.assertEquals(rc.getPath(), EResourceConstant.RULES_SQL.getPath());
}
Also used : WhereRule(org.talend.dataquality.rules.WhereRule) Test(org.junit.Test)

Example 9 with WhereRule

use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.

the class AElementPersistanceRealTest method testCreateItemWhereRule.

/**
 * Test method for
 * {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
 */
@Test
public void testCreateItemWhereRule() {
    DQRuleWriter createdRuleWriter = ElementWriterFactory.getInstance().createdRuleWriter();
    // test normal name
    // $NON-NLS-1$
    String whereRuleName = "whereRule1";
    // $NON-NLS-1$
    String exceptedFileName = whereRuleName + "_0.1.rules";
    WhereRule createWhereRule = RulesFactory.eINSTANCE.createWhereRule();
    createWhereRule.setName(whereRuleName);
    Item createItem = createdRuleWriter.createItem(createWhereRule);
    assertTrue(createItem instanceof TDQBusinessRuleItem);
    TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) createItem;
    assertTrue(ruleItem.getFilename().equals(exceptedFileName));
    // test special name
    // $NON-NLS-1$
    String whereRuleName2 = "whereRule1*\\/?";
    // $NON-NLS-1$
    String exceptedFileName2 = "whereRule1_____0.1.rules";
    WhereRule createWhereRule2 = RulesFactory.eINSTANCE.createWhereRule();
    createWhereRule2.setName(whereRuleName2);
    Item createItem2 = createdRuleWriter.createItem(createWhereRule2);
    assertTrue(createItem2 instanceof TDQBusinessRuleItem);
    TDQBusinessRuleItem ruleItem2 = (TDQBusinessRuleItem) createItem2;
    assertTrue(ruleItem2.getFilename().equals(exceptedFileName2));
}
Also used : TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) WhereRule(org.talend.dataquality.rules.WhereRule) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Test(org.junit.Test)

Example 10 with WhereRule

use of org.talend.dataquality.rules.WhereRule in project tdq-studio-se by Talend.

the class TableAnalysisSqlExecutor method createSqlQuery.

private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
    if (!isAnalyzedElementValid(indicator)) {
        return Boolean.FALSE;
    }
    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
    if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
        return Boolean.FALSE;
    }
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    if (!isExpressionValid(sqlGenericExpression, indicator)) {
        return Boolean.FALSE;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpressionDQRule = new ArrayList<String>();
    final EList<JoinElement> joinConditions = indicator.getJoinConditions();
    if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
        WhereRule wr = (WhereRule) indicatorDefinition;
        if (withWhereOfRule) {
            whereExpressionDQRule.add(wr.getWhereExpression());
        }
        // MOD scorreia 2009-03-13 copy joins conditions into the indicator
        joinConditions.clear();
        if (!isJoinConditionEmpty(indicator)) {
            for (JoinElement joinelt : wr.getJoins()) {
                JoinElement joinCopy = EcoreUtil.copy(joinelt);
                joinConditions.add(joinCopy);
            }
        }
    }
    NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
    String schemaName = getQuotedSchemaName(set);
    // --- normalize table name
    String catalogName = getQuotedCatalogName(set);
    if (catalogName == null && schemaName != null) {
        // try to get catalog above schema
        final Schema parentSchema = SchemaHelper.getParentSchema(set);
        final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
        catalogName = parentCatalog != null ? parentCatalog.getName() : null;
    }
    // --- default case
    // allow join
    String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
    String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
    String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
    // ~
    List<String> whereExpressionAnalysis = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpressionAnalysis.add(dataFilterAsString);
    }
    completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
    // completedSqlString is the final query
    String finalQuery = completedSqlString;
    TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
    indicator.setInstantiatedExpression(instantiateSqlExpression);
    return true;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) WhereRule(org.talend.dataquality.rules.WhereRule) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) TdExpression(org.talend.cwm.relational.TdExpression) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

WhereRule (org.talend.dataquality.rules.WhereRule)15 ArrayList (java.util.ArrayList)5 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)5 IFile (org.eclipse.core.resources.IFile)4 IFolder (org.eclipse.core.resources.IFolder)3 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)3 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)3 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)3 NamedColumnSet (orgomg.cwm.resource.relational.NamedColumnSet)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Test (org.junit.Test)2 Item (org.talend.core.model.properties.Item)2 TdExpression (org.talend.cwm.relational.TdExpression)2 Analysis (org.talend.dataquality.analysis.Analysis)2 Indicator (org.talend.dataquality.indicators.Indicator)2 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)2 WhereRuleIndicator (org.talend.dataquality.indicators.sql.WhereRuleIndicator)2 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)2 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)2 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)2